Trouble with MessageBox and OnActivate

Post » Sun Jun 12, 2011 4:18 am

So originally I was trying to do this as an object in the player's inventory; because I read Cast doesn't work that way, I changed it to an activator instead. Here is the current script:

ScN KDBHandActivatorScript

short Touched

Begin OnActivate

if Touched == 0
MessageBox "Success! The script is working!"
Set Touched to 1
endif

if Touched == 1
MessageBox "This is the first time."
Set Touched to 2
endif

if Touched == 2
MessageBox "This is the second time."
Set Touched to 3
endif

if Touched == 3
MessageBox "This is the third time."
MessageBox "Text too long for one box?"
Cast KDBHandCold Player
Set Touched to 3
endif

End

Both as an item and an object, I keep having problems with the boxes skipping around. I'll go to test it, and the first box I get will be 3, or 2, sometimes 1, etc. Also, if you have too much text for one MessageBox, is this a good way to split it up or is there a better way?
User avatar
El Goose
 
Posts: 3368
Joined: Sun Dec 02, 2007 12:02 am

Post » Sun Jun 12, 2011 10:15 am

So originally I was trying to do this as an object in the player's inventory; because I read Cast doesn't work that way, I changed it to an activator instead. Here is the current script:

ScN KDBHandActivatorScript

short Touched

Begin OnActivate

if Touched == 0
MessageBox "Success! The script is working!"
Set Touched to 1
endif

if Touched == 1
MessageBox "This is the first time."
Set Touched to 2
endif

if Touched == 2
MessageBox "This is the second time."
Set Touched to 3
endif

if Touched == 3
MessageBox "This is the third time."
MessageBox "Text too long for one box?"
Cast KDBHandCold Player
Set Touched to 3
endif

End

Both as an item and an object, I keep having problems with the boxes skipping around. I'll go to test it, and the first box I get will be 3, or 2, sometimes 1, etc. Also, if you have too much text for one MessageBox, is this a good way to split it up or is there a better way?


Use elseif after the first if command. EDIT: Use elseif for all other ifs after the first if.
User avatar
Bethany Watkin
 
Posts: 3445
Joined: Sun Jul 23, 2006 4:13 pm

Post » Sun Jun 12, 2011 9:22 am

Use elseif after the first if command. EDIT: Use elseif for all other ifs after the first if.

I just thought of that after posting. I changed it, went in-game, and activated, but I still got Box 3 on the first try. Do you know what else it might be?
User avatar
Haley Cooper
 
Posts: 3490
Joined: Wed Jun 14, 2006 11:30 am

Post » Sun Jun 12, 2011 12:27 pm

So originally I was trying to do this as an object in the player's inventory; because I read Cast doesn't work that way, I changed it to an activator instead. Here is the current script:

if Touched == 3
MessageBox "This is the third time."
MessageBox "Text too long for one box?"
Cast KDBHandCold Player
Set Touched to 3
endif



The underlined line is redundant. Consider changing or removing it.
User avatar
Jessie Rae Brouillette
 
Posts: 3469
Joined: Mon Dec 11, 2006 9:50 am

Post » Sun Jun 12, 2011 2:54 pm

The underlined line is redundant. Consider changing or removing it.

Sorry, that was supposed to say Set Touched to 4, to continue the pattern. Thanks for catching that.
User avatar
Jeffrey Lawson
 
Posts: 3485
Joined: Tue Oct 16, 2007 5:36 pm

Post » Sun Jun 12, 2011 4:16 am

Delete all the endif's then at the bottom put all of them there. When you use a endif that ends that block of script then tells the next block to start. It is making it happen without having to activate your item a second or third time.

Try this, be sure to save your work and rename the script so it doesn't override.

ScN KDBHandActivatorScript

short Touched

Begin OnActivate

if Touched == 0
MessageBox "Success! The script is working!"
Set Touched to 1

elseif Touched == 1
MessageBox "This is the first time."
Set Touched to 2

elseif Touched == 2
MessageBox "This is the second time."
Set Touched to 3

elseif Touched == 3
MessageBox "This is the third time."
MessageBox "Text too long for one box?"
Cast KDBHandCold Player
Set Touched to 4

endif
endif
endif
endif

End
User avatar
brian adkins
 
Posts: 3452
Joined: Mon Oct 01, 2007 8:51 am

Post » Sun Jun 12, 2011 7:30 am

Delete all the endif's then at the bottom put all of them there. When you use a endif that ends that block of script then tells the next block to start. It is making it happen without having to activate your item a second or third time.

Try this, be sure to save your work and rename the script so it doesn't override.

ScN KDBHandActivatorScript

short Touched

Begin OnActivate

if Touched == 0
MessageBox "Success! The script is working!"
Set Touched to 1

elseif Touched == 1
MessageBox "This is the first time."
Set Touched to 2

elseif Touched == 2
MessageBox "This is the second time."
Set Touched to 3

elseif Touched == 3
MessageBox "This is the third time."
MessageBox "Text too long for one box?"
Cast KDBHandCold Player
Set Touched to 4

endif
endif
endif
endif

End


You only need one endif here. There's no nested ifs to deal with.
User avatar
Josh Sabatini
 
Posts: 3445
Joined: Wed Nov 14, 2007 9:47 pm

Post » Sun Jun 12, 2011 7:02 am

Thanks, I just figured that out; I was using the elseif's improperly. So I've got the sequence working correctly now, any thoughts on how to do two MessageBoxes if you have too much text to fit in one? I was currently about to try:

elseif Touched == 3
MessageBox "Box 3"
if GetButtonPressed == 0
MessageBox "Box 3.5"
Cast KDBHandCold Player
Set Touched to 4
endif
endif
User avatar
Marcus Jordan
 
Posts: 3474
Joined: Fri Jun 29, 2007 1:16 am

Post » Sun Jun 12, 2011 6:30 am

You only need one endif here. There's no nested ifs to deal with.


I use it because I have longer scripts then most people :) It's just to show how many if commands I have and I can tell with nested endif's(of course they are tabbed for a staircase effect).

Also Korak_Karnar

elseif Touched == 3
MessageBox "Box 3"
set Touched to 4

elseif GetButtonPressed == 0 || Touched == 4 ;Does this line mean another button other then your activator is pressed?
MessageBox "Box 3.5"
Cast KDBHandCold Player
Set Touched to 5
endif
endif
User avatar
SaVino GοΜ
 
Posts: 3360
Joined: Mon Sep 17, 2007 8:00 pm

Post » Sun Jun 12, 2011 3:23 am

The major hurdle with that is that onActivate script blocks only run on the frame they have been activated, so you can't separate out the two messageboxes properly in that block. You could try adding in a gameMode block like this:

ScN KDBHandActivatorScriptfloat timershort TouchedBegin OnActivateif Touched == 0MessageBox "Success! The script is working!"Set Touched to 1elseif Touched == 1MessageBox "This is the first time."Set Touched to 2elseif Touched == 2MessageBox "This is the second time."Set Touched to 3elseif Touched == 3MessageBox "This is the third time."set timer to 1Set Touched to 4endifEndbegin gameModeif timer > 0set timer to timer - getsecondspassedelseif Touched == 4 && timer <= 0MessageBox "My text goes here"Cast KDBHandCold Playerset Touched to 5endifend


This way, on the fourth press of the button, a one second timer will start before the second messagebox is called up and the spell is cast.
User avatar
Cheville Thompson
 
Posts: 3404
Joined: Sun Mar 25, 2007 2:33 pm


Return to IV - Oblivion