One-time-only function

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.

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.

views:1371 update:2011/11/2 21:34:51
corona forums © 2003-2011