Seeking help with a script

Post » Mon Dec 08, 2014 12:12 am

I try to edit a script that takes into account the number of creatures killed in a log book. My problem is that a script contains only a certain amount of lines, so I need several scripts to perform the updates of the book, and i cannot seem to make them all run!

This is how the main script look:

begin tf_kills

short UpdateOn

if ( MenuMode == 1 )
return
endif

if ( OnActivate == 1 )
if ( Player->GetItemCount "Misc_Quill" > 0)
set UpdateOn to 1
else
messagebox, "You haven't any quill pen to update this journal."
activate
endif
endif

if ( UpdateOn == 1 )
StartScript "tf_animal"

StartScript "tf_ash"

StartScript "tf_daedra"

StartScript "tf_other"
StartScript "tf_undead"
; ACTION READ
set UpdateOn to 0
messagebox, "Achievements updated"
activate
endif

end tf_kills

And for the startscripts i just copy/paste the main script changing only the "StartScripts" by the "getdeadcount" list of all the creatures...

Any comments will be desperatly appreciated!

User avatar
Madison Poo
 
Posts: 3414
Joined: Wed Oct 24, 2007 9:09 pm

Post » Sun Dec 07, 2014 7:50 pm

Welcome to the forums, fantomas.

I suppose the satellite scripts are merely updating global variables that store the body count that the text in your book references.

When a global script is started with Startscript it basically triggers the frame to repeat. All scripts that previously ran will do so again; in particular tf_kills. It may be that as soon as the line StartScript "tf_animal" processed tf_kills reruns from the beginning without finishing the current cycle. If that is the case, then when it gets to StartScript "tf_animal" the whole process repeats preventing the script from ever processing the rest of your code (the other StartScripts). If the message "Achievements updated" is not displaying that may be a confirmation of what I am supposing.

There may be a couple solutions, but one is just better practice and you should do if even if you opt for the second approach. The check if ( ( ScriptRunning "tf_animal" ) == 0 ) is a precaution that can prevent a variety of weirdness from happening, but it also means that when tf_kills recycles it will skip StartScript "tf_animal" since it will already be running and go to StartScript "tf_ash" (which should run inside a check for that script running)... and so on.

The other approach is to daisy-chain the satellite scripts rather than call all of from tf_kills. Only tf_animals is called from the main script. Move the line StartScript "tf_ash" to tf_animal to call if from that script, and so on until all of your satellite scripts have been called by their predecessors. Again it is good practice to check for the script running before you start is unless there is absolutely no chance that it could be running.

I am making some assumptions about how tf_kills behaves when StartScript is called. If I am wrong then what I propose may not solve your problem, but at least the ScriptRunning checks should be included in your code in any case. If you cannot get things working you should post tf_animals so we can examine its logic.

User avatar
Darren Chandler
 
Posts: 3361
Joined: Mon Jun 25, 2007 9:03 am


Return to III - Morrowind