Scripting Barrel Error

Post » Tue Dec 29, 2009 12:23 pm

I'm working on my first mod, and I'm working on a container. I've come to a standstill and I can't figure out what I'm doing wrong. I think that it's a fairly simple fix, but I'm really inexperienced with this. What I want is that when you go to open the container, a message box opens up with buttons on it. When you click on either button, it goes to the inventory of the container.

As it is, I couldn't get it to work, so I created a new container, and told Morrowind to force the new container to open up when I clicked on one of the message box buttons. Here is what I'm working with.

begin BriggsMessageTest	short MessageOn	short Button			; Display message when the player activates the object	If ( OnActivate == 1 )	set MessageOn to 1	endif			; Display the choices to the user	if ( messageOn == 1 )		MessageBox, "Tara eats her soda.  Tara drinks her oatmeal. Tara loves tiaras.", "Milk Soda", "Three Ninjas 6: Revenge of Grampa's Family"				Set messageOn to 2	endif	if ( messageOn == 2 )					set Button to GetButtonPressed								if ( Button == -1 )				Set MessageOn to 0		elseif ( Button == 0 )			Set MessageOn to 0		elseif ( Button == 1 )			Set MessageOn to 0		endif	endif"briggs_barrel_03"->Activate, playerend


I've done a lot of looking online for how to do this, and some of the code I've found just seems redundant, including what I have right now. I hope someone knows what I'm doing wrong.
User avatar
Betsy Humpledink
 
Posts: 3443
Joined: Wed Jun 28, 2006 11:56 am

Post » Tue Dec 29, 2009 10:10 am

Here's what I would use:

Begin BriggsMessageTestshort doonceif ( OnActivate == 1 )	Messagebox, "Question", "Answer 1", "Answer 2"	set doonce to -1	Returnendifif ( doonce == 0 )	Returnendifset doonce to GetButtonPressedif ( doonce == -1 )	ReturnendifActivateset doonce to 0End



The problem with your script is most likely this part:

if ( Button == -1 )     	Set MessageOn to 0elseif ( Button == 0 )	Set MessageOn to 0elseif ( Button == 1 )	Set MessageOn to 0endifendif"briggs_barrel_03"->Activate, player

It appears that your script has the same reaction to pressing the first button (0), pressing the second button (1), and not pressing any buttons (-1). Also the activation takes place outside of the if structures where it should be in order to react to the player pressing one of the buttons.

A fixed version of your above code snippet could be:

if ( Button == -1 )elseif ( Button == 0 )	"briggs_barrel_03"->Activate, player	Set MessageOn to 0elseif ( Button == 1 )	"briggs_barrel_03"->Activate, player	Set MessageOn to 0endif

Notice how nothing happens until the player presses a button.

Hope this will help. :)
User avatar
Vicki Gunn
 
Posts: 3397
Joined: Thu Nov 23, 2006 9:59 am

Post » Tue Dec 29, 2009 9:05 pm

Thank you so much. I always try to do things myself for a while before I rely on a forum, and I was stuck on this for a few days. I haven't tried it yet, but I'm confident in your advice.
User avatar
FLYBOYLEAK
 
Posts: 3440
Joined: Tue Oct 30, 2007 6:41 am

Post » Tue Dec 29, 2009 1:20 pm

I just put the code in. It does everything, but the container only stays open for one frame.

I think it's cause it goes "Activate" straight to "set doonce to 0" without anything in between. Then, because doonce = 0, it "Return"s...
User avatar
Sebrina Johnstone
 
Posts: 3456
Joined: Sat Jun 24, 2006 12:58 pm

Post » Tue Dec 29, 2009 1:31 pm

Ah yes, I've tested this and it seems that the container mustn't be activated in the same frame the button is pressed, because then the message box closes the container as well. It works however if you activate the container in the next frame, like so:

Begin BriggsMessageTestshort doonceif ( doonce == 2 )	Activate	set doonce to 0	Returnendifif ( OnActivate == 1 )	Messagebox, "Question", "Answer 1", "Answer 2"	set doonce to -1	Returnendifif ( doonce == 0 )	Returnendifset doonce to GetButtonPressedif ( doonce >= 0 )	set doonce to 2endifEnd

User avatar
Juan Cerda
 
Posts: 3426
Joined: Thu Jul 12, 2007 8:49 pm

Post » Tue Dec 29, 2009 6:29 am

So you're making the frame after the buttonpress be where the game determines what number "doonce" is, and then the next frame opens up the container. Thank you so much. It works great. The process being this ridiculous to perform such a seemingly simple task is kind of discouraging, but at least the rest of my mod is basically just going to be adding books, haha.
User avatar
Life long Observer
 
Posts: 3476
Joined: Fri Sep 08, 2006 7:07 pm

Post » Tue Dec 29, 2009 6:50 pm

Well, it's true there are a few pitfalls in Morrowind scripting, but they aren't all that common as to make scripting impossible. So don't let that discourage you.

And if you do run into one of them, you can always ask for help. :)

The http://planetelderscrolls.gamespy.com/View.php?view=Mods.Detail&id=6083 is a good place to start, it's a very helpful and very comprehensive guide. It has lots of example scripts and it's also easy to search in case you're looking for a particular scripting solution.
User avatar
tiffany Royal
 
Posts: 3340
Joined: Mon Dec 25, 2006 1:48 pm

Post » Tue Dec 29, 2009 6:46 pm

That's beautiful. I was using the modding pages on uesp.net which is pretty good, but this is just phenomenal.
User avatar
Alan Whiston
 
Posts: 3358
Joined: Sun May 06, 2007 4:07 pm


Return to III - Morrowind