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.
Label: corona android iphone ipad building error inmobi problem display screen View image tableView failed object physics touch button game lua config event listener |
One-time-only function
yes
do not call it any other time.
so
1 2 3 4 5 6 7 8 9 10 11 | 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() |
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 {:^)
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
1 | local isWelcomed = false |
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" ;-)
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,
?:)
OK. Thanks for all the help!
Much appreciated,
J.C.
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
Joints
Using Dynamic Image Resolution without Dynamic Content Scaling
Butterfly Adventures
dynamic scaling content (dsc)
accessing elements/groups in for loop
iPad Game Video Creation?
Amazon Store - Views of a Developer (not me)
Birdsong Quiz / Vogelstimmenquiz
Want a TabBar in your app?