Writing a Multi-Stage Message Box

Post » Fri Sep 02, 2011 7:43 pm

Fellow modders,

So I got sick and tired of doing nothing at the Arcane University, and decided to revive an idea of creating a small university program within the building proper. The program includes several "exams" which must be administered through Message Boxes.

Only problem is, I've never dealt with Multi-Layered Message Boxes before, much less the fact that there are nearly 20 of them in sequence. So I started a script up, but for some reason it runs improperly and I can't tell why.

Begin OnActivateif IsActionRef player == 1 && DoOnce == 0	MessageBox "Once you begin the test, you cannot stop until you finish the last question.  Are you ready to begin?", "No" "Yes"	set Doonce to 1	set Button to -1endifEndBegin Gamemodeset Button to GetButtonPressedif ( Button == 1 ) && ( DoOnce == 1 )MessageBox "What is Spellcraft?", "The study of casting and working spells""The act of casting and working spells""The ability to cast and work spells"set Button1 to GetButtonPressedelseif ( Button == 0 )set Doonce to 0endifendifif ( Button1 == 2 ) && ( DoOnce == 1 )set ButtonPressed1 to 1set rightanswer to rightanswer + 1elseif ( Button1 == 1 )set ButtonPressed1 to 1elseif ( Button1 == 0 )set ButtonPressed1 to 1endifendifendifif ButtonPressed1 == 1 && ( DoOnce == 1 )MessageBox "Finish the sentence: Never forget that Magicka...", "is both beneficial and detrimental""is a power of its own accord""is unfit for mortals"set Button2 to GetButtonPressedset ButtonPressed1 to 2endif


Any help?

Thank you,

Kroot
User avatar
Jack
 
Posts: 3483
Joined: Sat Oct 20, 2007 8:08 am

Post » Fri Sep 02, 2011 5:21 pm

The excess of endif's probably isn't helping. If ... elseif ... elseif ... else... endif only needs one at the end. I'd have expected errors when you tried to save the script for those.

You could also take all the "set ButtonPressed1 to 1" lines out, and put just one after the endif, as you're doing the same thing for every possibility.

If I were doing it, I'd have all the MessageBox stuff in gamemode, and just set a flag in the OnActivate block to indicate the whole thing needs to start up, but it should work this way too.
User avatar
Emerald Dreams
 
Posts: 3376
Joined: Sun Jan 07, 2007 2:52 pm

Post » Fri Sep 02, 2011 10:34 pm

Perhaps I should clarify. The problem is the second message box "What is Spellcraft", and any other boxes don't show up after the first. For some reason it totally skips over it. Is there some kind of reason the boxes aren't progressing correctly.

Thanks,

Kroot
User avatar
Emma Pennington
 
Posts: 3346
Joined: Tue Oct 17, 2006 8:41 am

Post » Fri Sep 02, 2011 4:01 pm

I can't think of how to explain it properly, but you're doing it wrong. You should only use GetButtonPressed inside of some if conditions to avoid it running all the time, and you should probably separate the MessageBox and GetButtonPressed commands so that they don't run one right after the other. This is an edited version of what you posted, and it should work properly:

Begin OnActivate	if (IsActionRef Player)		set rightanswer to 0		set menu to 1	endifEndBegin Gamemode	if (menu == 0)		Return	endif		if (menu == 1)		set menu to -1		MessageBox "Once you begin the test, you cannot stop until you finish the last question.  Are you ready to begin?", "No" "Yes"	elseif (menu == -1)		set button to GetButtonPressed		if (button == 0)			set menu to 0		elseif (button == 1)			set menu to 2		endif		Return	endif		if (menu == 2)		set menu to -2		MessageBox "What is Spellcraft?", "The study of casting and working spells""The act of casting and working spells""The ability to cast and work spells"	elseif (menu == -2)		set button to GetButtonPressed		if (button < 0)			Return		elseif (button == 2)			set rightanswer to rightanswer + 1		endif		set menu to 3		Return	endif		if (menu == 3)		set menu to -3		MessageBox "Finish the sentence: Never forget that Magicka...", "is both beneficial and detrimental""is a power of its own accord""is unfit for mortals"	elseif (menu == -3)		set button to GetButtonPressed		if (button < 0)			Return		elseif (button == *right answer*)			set rightanswer to rightanswer + 1		endif		set menu to 4		Return	endif	;	etc.End

User avatar
Emma Copeland
 
Posts: 3383
Joined: Sat Jul 01, 2006 12:37 am


Return to IV - Oblivion