Hey everyone, I was wondering if there is a way to make a function happen the first time you start a level, but not any other time.
[import]uid: 66117 topic_id: 17122 reply_id: 317122[/import]
Hey everyone, I was wondering if there is a way to make a function happen the first time you start a level, but not any other time.
[import]uid: 66117 topic_id: 17122 reply_id: 317122[/import]
yes
do not call it any other time.
so
local function theFunctionOnStart()
print("This is called at the start of the app only")
end
..
..
..
--define the rest of your stuff, if you use director or whatever
theFunctionOnStart()
Place this in your main.lua file
cheers,
?
[import]uid: 3826 topic_id: 17122 reply_id: 64419[/import]
thanks for the info JayantV, but I guess I should have been more specific.
My game is kinda like Lane Splitter, where you only have one “level”
that you keep playing over and over again… what if I wanted to
have a text that says “Welcome to Lane Splitter” the first time the player starts the level, but, since he will play it multiple times, (and he will already have been welcomed) I wouldn’t want it to happen again? : )
P.S. Sorry about the misunderstanding, I’ve updated the post {:^) [import]uid: 66117 topic_id: 17122 reply_id: 64492[/import]
In that case you need to persist (save the value of that variable to disk) I had a library called the PropertyBag which I have revoked, now you can use ICE from Graham Ranson which is a good alternative and uses SQLite.
Everytime you star the app, retrieve the value of the variable from the database/data file, if you do not get any value i.e. not set, then the value is false/nil anyways.
so when you print the welcome, save the variable to the database as set.
then no matter how many times you refresh the simulator, you will not get the message popping up.
cheers,
?
[import]uid: 3826 topic_id: 17122 reply_id: 64497[/import]
Ah that makes much more sense…
You need to look at this post here This is about flags and booleans and what you are describing is a perfect case where one would use a flag/boolean.
so at the start of your project have
local isWelcomed = false
then in your other function, lets say renderLevel
local function showWelcomeMessage()
print("Welcome to my app only for this time...")
end
local function renderLevel()
if not isWelcomed then
isWelcomed = true
showWelcomeMessage()
end
end
Now you can call the renderLevel function as many times as you want and the welcome message will be displayed only once.
cheers,
?
[import]uid: 3826 topic_id: 17122 reply_id: 64493[/import]
Well, it works. As long as i stay in the game, it doesn’t happen multiple times… but when i relaunch the simulator (or go to the main menu, then go back to the game), it prints it again. : (
Much appreciated,
J.C.
P.S. One of the words “message” is missing an “s”
[import]uid: 66117 topic_id: 17122 reply_id: 64496[/import]
OK. Thanks for all the help!
Much appreciated,
J.C. [import]uid: 66117 topic_id: 17122 reply_id: 64498[/import]