Launching a script, stopping a timer
Launching a script, stopping a timer
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 ?
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
You simply add another connector to the timer, pointing to the timer itself, and "deactivating" itzanreth wrote:QUERY: How do I make the timer and/or script from activating past the 1st (and only) iteration ?
alois
Re: Launching a script, stopping a timer
Thank you Alois, that works fine. Now I'm in business
Re: Launching a script, stopping a timer
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.zanreth wrote:Thank you Alois, that works fine. Now I'm in business
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
Code: Select all
-- Just your instructions, with no function block
Re: Launching a script, stopping a timer
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:
This way code is still inside the function, so locals will go out of scope when it finishes.
Code: Select all
function MyInitPc()
-- Your instructions
end
MyInitPc()
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.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Launching a script, stopping a timer
That's true.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:This way code is still inside the function, so locals will go out of scope when it finishes.Code: Select all
function MyInitPc() -- Your instructions end MyInitPc()
(And a thing that I forgot about! That's how I defined a lot of items in the OORR2. )
Re: Launching a script, stopping a timer
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!
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
"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
Re: Launching a script, stopping a timer
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) ?
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
Case sensitive; try:zanreth wrote:The error reads: "Attempt to call global 'hudprint' (a nil value) ?
hudPrint(" ")
Re: Launching a script, stopping a timer
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.
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
"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades