Launching a script, stopping a timer

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
zanreth
Posts: 12
Joined: Fri Aug 22, 2014 2:22 am
Location: Montreal

Launching a script, stopping a timer

Post 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 ?
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: Launching a script, stopping a timer

Post 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 :)
User avatar
zanreth
Posts: 12
Joined: Fri Aug 22, 2014 2:22 am
Location: Montreal

Re: Launching a script, stopping a timer

Post by zanreth »

Thank you Alois, that works fine. Now I'm in business :-)
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Launching a script, stopping a timer

Post 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
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Launching a script, stopping a timer

Post 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.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Launching a script, stopping a timer

Post 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: )
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: Launching a script, stopping a timer

Post 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!
Last edited by msyblade on Mon Aug 25, 2014 4:01 pm, edited 1 time in total.
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
User avatar
zanreth
Posts: 12
Joined: Fri Aug 22, 2014 2:22 am
Location: Montreal

Re: Launching a script, stopping a timer

Post 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) ?
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Launching a script, stopping a timer

Post by Isaac »

zanreth wrote:The error reads: "Attempt to call global 'hudprint' (a nil value) ?
Case sensitive; try:

hudPrint(" ")
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: Launching a script, stopping a timer

Post 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:
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
Post Reply