Jump to content

Keep variables on map change


Angelwolf
 Share

Recommended Posts

I'm wondering if anyone can tell me how I can keep variables when changing maps.

 

For example, if a player has 50 hit points and goes to the next map, I would like that player to remain with 50 hit points rather than having them reset to 100 when the next map loads.

Link to comment
Share on other sites

To build on josk's answer if you do go global variables (I would maybe look at file i/o for this unless you want it to work on the game player) make a global table and store the values in there inside Main.lua. It'll just be easier to organize things that way vs loose variables.

  • Upvote 2
Link to comment
Share on other sites

If i add the variable Josk suggested, how do i call that variable in FPSPlayer.lua?

 

Im assuming its Script.heath = HitPoints, but that doesnt seem to work.

 

Edit:

Ok, I literally used find and replace in FPSPlayer.lua for self.health to Hitpoints, which made it work. Thank you!

 

One other thing though, How exactly would I go about using file i/o?

Link to comment
Share on other sites

I wouldn't be in a hurry to use file i/o if you are just using LUA, as that would probably preclude the use of the game player, which requires sand pit mode, and using file i/o will probably mean you cant get your game published as easily. If you have a requirement for file i/o and it would be general purpose and safe, Josh may code some new api, to wrap up your functionality that would then allow that to be added, like he did for the high score board.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...