Page 1 of 2

Launching a script, stopping a timer

Posted: Fri Aug 22, 2014 5:56 pm
by zanreth
Hello All,
Newbie question here. Been learning scripting for the past two days and I'm hitting some challenges I can't seem to resolve or find answers on these forums. So here goes:

I have this script designed to "wipe" the default party and create a custom party of four champions for my mod dungeon. So far, the script works in facts that it does what it needs to: sets the champions names, race, class, portraits, equips them with the gear I want them to have, even gives them some skill spoints (gives 10 skill points to each champions to be assigned by the player) to raise their abilities a bit.

My script is launched through a TIMER. I have a timer set to a 1-second delay that begisn the game activated. This means (I think) that once the game launches/spawns, the timer runs it's 1-second delay and then launches my script, which creates the party. It all happens within 1-second from game star, so it's "transparent" to the player.

My BUG: The timer seems to keep running, which means it re-launches the script every seconds!! The effect is that the 10 skills points keep incrementing every seconds and the champions keep "levelling" forever ...

QUERY: How do I make the timer and/or script from activating past the 1st (and only) iteration ?

Re: Launching a script, stopping a timer

Posted: Fri Aug 22, 2014 6:08 pm
by alois
zanreth wrote:QUERY: How do I make the timer and/or script from activating past the 1st (and only) iteration ?
You simply add another connector to the timer, pointing to the timer itself, and "deactivating" it :)

alois :)

Re: Launching a script, stopping a timer

Posted: Fri Aug 22, 2014 6:21 pm
by zanreth
Thank you Alois, that works fine. Now I'm in business :-)

Re: Launching a script, stopping a timer

Posted: Fri Aug 22, 2014 7:43 pm
by Isaac
zanreth wrote:Thank you Alois, that works fine. Now I'm in business :-)
Timers [as was just mentioned] can be used to trigger themselves to deactivate, but you shouldn't need a timer for a one time initialization script.

Have you tried just removing the enclosing function block from your script; (and forget the timer).
This should simply run the code when the game loads.

*Meaning:

Code: Select all

function MyInitPC()
-- Your instructions
end
To this instead:

Code: Select all

-- Just your instructions, with no function block

Re: Launching a script, stopping a timer

Posted: Fri Aug 22, 2014 8:17 pm
by minmay
Note that Isaac's solution won't allow you to use any temporary variables (trying to save upvalues OR references to anything not a table/string/number/bool will cause a crash). Therefore I prefer to do this:

Code: Select all

function MyInitPc()
-- Your instructions
end
MyInitPc()
This way code is still inside the function, so locals will go out of scope when it finishes.

Re: Launching a script, stopping a timer

Posted: Fri Aug 22, 2014 8:52 pm
by Isaac
minmay wrote:Note that Isaac's solution won't allow you to use any temporary variables (trying to save upvalues OR references to anything not a table/string/number/bool will cause a crash). Therefore I prefer to do this:

Code: Select all

function MyInitPc()
-- Your instructions
end
MyInitPc()
This way code is still inside the function, so locals will go out of scope when it finishes.
That's true.
(And a thing that I forgot about! That's how I defined a lot of items in the OORR2. :oops: )

Re: Launching a script, stopping a timer

Posted: Fri Aug 22, 2014 10:02 pm
by msyblade
This is also how you eliminate the "First time playing Grimrock?" text at the start. Create a script, no function, and give it 4 hudPrints, blank or with a message you want to add.

ie:

hudPrint ""
hudPrint ""
hudPrint ""
hudPrint ""

will make no message, or:

hudPrint ""
hudPrint ""
hudPrint "You awaken in a strange place."
hudPrint "Contar: We need to find our gear!"

will make a 2 line message at the start.

Hope it helps!

Re: Launching a script, stopping a timer

Posted: Sun Aug 24, 2014 12:34 pm
by zanreth
Thank you all for your input, it's helped a lot!

msyblade: Can you detail a bit more ? I tried that (4x blank lines as indicated) into a blank script, no functions, no timer, and I get an error message in the editor when I run the dungeon.

The error reads: "Attempt to call global 'hudprint' (a nil value) ?

Re: Launching a script, stopping a timer

Posted: Mon Aug 25, 2014 5:51 am
by Isaac
zanreth wrote:The error reads: "Attempt to call global 'hudprint' (a nil value) ?
Case sensitive; try:

hudPrint(" ")

Re: Launching a script, stopping a timer

Posted: Mon Aug 25, 2014 4:06 pm
by msyblade
I was going to write a reply to the effect of "camelHumpIsACommonFormatToSeperateWordsWithoutSpaces. youMustAlwaysPayCloseAttentionToTheseSimpleCapitalizations." Then I noticed that I had just copy/pasted all 8 examples from the first, which was not capitalized correctly (edited now). Soooo, Carry on. . . Nothing to see here. . .(whistling nonchalantly). Thanx Isaac. :oops: