I'm extremely confused and bewildered and on and off with Construct, so once again I have a question. Is there a way to have a function run once? I honestly assumed that they did run once (since they are functions). I may be missing something, I do not know.
Basically, I have been trying to make a message box that would appear once and be called anytime. Basically I have an event sheet that holds the functions for the game.
On page 1 (The layout that sets stuff up), I have this
> File "gmdat" does not exist:
My function: Add parameters (The parameters for the message box)
Call function: myfunction (Forget picked objects)
[/code:3p8a5rqj]
On my page that contains the functions, one being for the message box,
[code:3p8a5rqj]
System: Create the Infobox object at params (3), (4) (x and y)
System: Create a second instance of "Text" at Infobox's pivot point (Now there are only two instances of text, or there should be).
Text: Set height to param(5)
Text: Set width to param(6) - 30
Text: Set text to param(7)
[/code:3p8a5rqj]
In theory, I should be able to then do this in Python:
[code:3p8a5rqj]
Text[1].Text = "This is a test."
[/code:3p8a5rqj]
...since only one additional instance is made (I was forced to do it by the editor just to have it a global object that I can pull up anytime). The python script is in a sub event.
Now here is where the problem comes in. When I put line of script in, anything above Text[0].Text did not work and gave me an error. I looked at the debugger and also saw that the game was creating an infinite amount of instances of "Infobox" and "Text".
So I must ask, is there any way to have a function to run once (or is that impossible)? Also, why is the Python not grabbing other instances beyond the first?
A function is executed when you call it. If you call it once, it will be executed once. Events are checked on every tick. If its condition is true, the event will be executed.
If 'File "gmdat" does not exist:' means that you check for the absence of a file then this condition will be true on every tick unless a file "gmdat" is created.
Tick 1: Does the file exist? No. Call function
Tick 2: Does the file exist? Still no. Call function again
etc.
To prevent calling the function more than once, create a global or private variable and use it as a switch. Set it to 0 when creating, then in your 'File "gmdat" does not exist:' add the condition my variable = 0
and add the action 'add 1 to my variable'
Now the event will only become true the first time it is checked and the function will only be called once.