Is there any way to have a script run ONCE?

Started by Clean0nion, December 19, 2013, 07:29:21 PM

Previous topic - Next topic

Clean0nion

Hi guys! I'm new to this forum and this is my first post, so be kind please!

Is there any way to have a script run once?
For example, there is the obvious once -- endonce function, and things such as :Gameloaded and :Awake, but none of those do what I want, because they can repeat after the map is reloaded.

What I want is this:
- The game is loaded.
- The script immediately runs.
- It does not run again, even if the map is restarted.

The reason that I want this is because I have a fancy opening sequence.
Can anyone help?

Lost in Nowhere

As far as I'm aware, once -- endonce only runs when the scripts are recompiled, variables are changed, or the script has not yet run.
Don't die! :)

kwinse

Alternatively, destroy the core after it runs the script.

Annonymus

If you really want a way to not do it again even when the map is restarted, I think there is no way to do that...
Except...
Maybe you can do something with the dialogues that pop up when you first play a map, these don't show up a 2. time even if you restart a map, so if you find a way to check if those dialogues have already been seen you could do this.
Then you just need a way to get in a dialogue without making it creepy (because when the dialogue finishes another (your CRPL one) pops up...)
If a topic started by me is in the wrong place feel free to move it at anytime.

knucracker

A once/endonce section only runs once.  During development these sections gets reset when you recompile.  But for a released map a once/endonce section only executes once.  This is true across save/load cycles.

If you want something that only runs twice (for example). Then you can do it with a variable yourself that you check.  Variables get saved and loaded so if you have a variable named "executionCount" its count gets persisted in save file.  That's basically how the once/endonce section is implemented internally (the count vars are implicitly created for you in internal structures).

Grauniad

My thinking is if you get a key then you can check on the key and perhaps the core won't run again. Keys are persistent across map runs.
A goodnight to all and to all a good night - Goodnight Moon

Grauniad

Quote from: Annonymus on December 20, 2013, 06:04:10 AM

Maybe you can do something with the dialogues that pop up when you first play a map, these don't show up a 2. time even if you restart a map,

Just on a point of clarification, you do know these are in the "Archived Transmissions" button in the Orbital section, right?
A goodnight to all and to all a good night - Goodnight Moon

Clean0nion

#7
Here's what I'm thinking so far.

Annonymous, your solution, as far as I know, isn't possible. I can check whether the conversation is showing or not, and that's it. However, my intro uses dynamically-created chat. So that's not possible for me even if the CRPL allowed it.

Grauniad, as far as I know keys can only be permanently collected if the map is beaten with it. So that's not viable either.

Virgil, your solution makes sense less. If a once -- endonce function is only ever run once per map, then that must mean that variables set in said once -- endonce function must persist across saves too? Unless more :GameLoaded functions are being used than I think.
But if variables persist across saves and loads, that is very interesting. Unless you can confirm this now, I'll run a few tests and see if it does persist.
And thinking of that - is this what the NotPersist command does? It makes a variable not persist across saves?

EDIT: Added NotPersist to the wiki

thepenguin

Quote from: Clean0nion on December 20, 2013, 10:03:15 AM
Virgil, your solution makes sense less. If a once -- endonce function is only ever run once per map, then that must mean that variables set in said once -- endonce function must persist across saves too? Unless more :GameLoaded functions are being used than I think.
But if variables persist across saves and loads, that is very interesting. Unless you can confirm this now, I'll run a few tests and see if it does persist.
And thinking of that - is this what the NotPersist command does? It makes a variable not persist across saves?
they do.  you are right on all counts here.  They persist in saves unless told to do otherwise.
We have become the creeper...