Script Issues...

Post » Mon Nov 23, 2009 10:46 pm

This is my first script and I cannot seem to get it to work, any help one could give me would be greatly appreciated, as well as any advice one could give to a starting Modder. Anyway, this script is supposed to be able to make the player get money and stat boosts from working for different NPC via a notice in the NPC's shop...

Begin 00_SmithyNoticeScript_00
Float GameHour
Short OnActivate
Short MessageOn
Short Button

If ( OnActivate == 1 )
Set MessageOn to 1
Endif

If ( MessageOn == 1 )
MessageBox, "Help Wanted, need help Smithing. Requirements, Strength 40, Endurance, 45. Pay is 50 Drakes every six hours. Do you want to apply?", "Sure", "Not today"
Set MessageOn to 2
Endif

If ( MessageOn == 2 )
Set Button to GetButtonPressed
If ( Button == -1 )
Return
Endif

If ( Button == 0 )
Player->Additem, "Gold_001", 100
Player->ModArmorer 1
Set GameHour to GameHour +6
Endif

If ( Button == 1 )
Set MessageOn to 0
Return
Endif
Endif
End



I have not gotten the requirements in yet, however I cannot even get the MessageBox to pop up, let alone see any stat upgrades or time changes...
User avatar
Paula Ramos
 
Posts: 3384
Joined: Sun Jul 16, 2006 5:43 am

Post » Tue Nov 24, 2009 1:10 am

Your syntax and structure is basically sound - a good first attempt at scripting, but you stumbled over OnActivate (and probably GameHour as well).

OnActivate (I wish this forum didn't change my capitalization) is not a variable to be declared. It is more of a function that returns a value of 1 (true) when the object to which the script is attached is activated. When you declare short OnActivate now all references to OnActivate will look to a value stored in the local variable by that name and not the function OnActivate. Since at no time is the local short variable OnActivate set to 1 your message never displays.

GameHour is an officially declared global variable that keeps track of time. if you intend to reference that global variable you must not declare it as a local float variable in your script. Again, locally declared variables trump functions and global variables making the latter inaccessible by your script.

You will also get an error on the line Set GameHour to GameHour +6. There needs to be a space between '+' and '6': Set GameHour to GameHour + 6. I cannot remember with certainty the results of my own tests as to what will happen if GameHour is greater than 18 when this is done. I know it will adjust it to be less than 24 (e.g. if GameHour equals 20, then GameHour + 6 equals 2, but I do not recall if it increased Day by one to the next day. Just check for it in your tests. It is one of the reasons I am a little nervous about changing GameHour in my scripts. There is also some uncertainly what your changes could do to other scripts running that are checking GameHour.

I notice that for if ( Button == 0 ) you do not reset MessageOn to 0. That probably does not matter since when you fix (not declare) OnActivate MessageOn will the set to display the message anyway. However there is a little room for improvement in the structure of that part of your script. Something like:

If ( MessageOn == 2 )    Set Button to GetButtonPressed    If ( Button == -1 )        Return    ElseIf ( Button == 0 )        Player->Additem, "Gold_001", 100        Player->ModArmorer 1        Set GameHour to GameHour +6    ElseIf ( Button == 1 ) ; nothing need be done    EndIf    Set MessageOn to 0    ReturnEndIf

Since you asked, here are a couple of links to the principal scripting resources used by modders:

http://www.tamriel-rebuilt.org/files/tuts/MWSFD90_Word.zip

http://www.uesp.net/wiki/Tes3Mod:Modding

There are many tutorials linked from the pinned threads at the top of this forum, and of course you are always welcome to post questions you have in this forum. There are many capable members of our community who are willing to help. The first link takes you to Tamriel Rebuilt's website that offers many excellent tutorials and utilities for modders.

Although you didn't ask for it, I will also offer my own thoughts about what you are trying to achieve. By all means complete the script and revel in the success of it, but it is a little silly for a note to hire and compensate the player for a job. This would be more logically achieved through dialog with an NPC that hires the player. Dialog would handle whether or not the player accepts the job, and if the player does, then dialog results (or a global script started from dialog results) would pay the player and advance time. It is a simple matter to add the attribute checks for strength and endurance as dialog filters. You can also introduce a FadeOut and FadeIn to simulate the passage of time. This can be done in your original scripted solution as well. You might also consider adding a messagebox declaring that the player's armorer skill has increased. Whichever approach you decide to take with your project good luck.

Postscript: Don't talk about my mother. :angry: ;)
User avatar
asako
 
Posts: 3296
Joined: Wed Oct 04, 2006 7:16 am

Post » Tue Nov 24, 2009 2:22 am

That's a pretty rightous reponse, and thank you for the elaborate explanation. Honestly I was thinking the same thing with the note but as this is my first mod I did not want to get too elaborate, as this is mostly for practice... anyway thanks again for your help, it makes a big difference how you explain the things behind it, I'll check out the links. Is there an actual book for Morrowind Scripting for Dummies by any chance. Is there another way to advance time without using the GameHour command?
User avatar
Blessed DIVA
 
Posts: 3408
Joined: Thu Jul 13, 2006 12:09 am

Post » Mon Nov 23, 2009 3:25 pm

There have been two version of Morrowind Scripting for Dummies (MSFD) in the past: an MS Word version and a PDF version. I do not recall if both are still available (I use the Word version). I prefer a hard copy as well, but the only printed version I have is five-six years old. I still use it, but if I need more current information I open the Word document for version 9.0. MSFD has an effective organization shown in its table of contents, and there is an index for script functions (and a few other features) at the end of the document. If you know the function you want (or near enough) you can look it up in the index to get the page number that will describe the syntax and any other issues associated with the function. When you are first starting out, the table of contents will be more helpful.

There may not be a reasonable alternative to setting a value to GameHour, but it may not be as great a concern as I implied. Most mods that are going to be monitoring GameHour should do fine and any mod that also writes to it will not likely have that feature active when the player is 'working'. The real concern I had was whether Day updates if GameHour is set to a value beyond 24. I have just finished testing this and while the day does advance GameHour is set to 0 when the day turns over regardless of how close to midnight it started. I checked twice:

Starting: Day = 16, GameHour = 20
After setting GameHour to ( GameHour + 6 ): Day = 17 GameHour = 0

Starting: Day = 16, GameHour = 22
After setting GameHour to ( GameHour + 6 ): Day = 17 GameHour = 0

This means you will have to be more creative. Check GameHour. If it is less than 18 there is no problem. If it is greater than 18 you will have to store the difference in a float variable, and then add that difference to GameHour after the script updates Day and adjusts GameHour to 0.

Postscript: I neglected to welcome you to the forums yesterday. Have a http://www.mwmythicmods.com/fishy.htm
User avatar
RUby DIaz
 
Posts: 3383
Joined: Wed Nov 29, 2006 8:18 am


Return to III - Morrowind