Angelwolf Posted November 9, 2015 Share Posted November 9, 2015 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. Quote My Games: Nightmare Prism:::WolfTale:::Dungeon Creeper:::Despair of Ordinary Men:::Piano Simulator 2016:::House (W.I.P) Link to comment Share on other sites More sharing options...
Wedmer Posted November 9, 2015 Share Posted November 9, 2015 So you have to create some global values and sync to them. Quote Link to comment Share on other sites More sharing options...
Angelwolf Posted November 9, 2015 Author Share Posted November 9, 2015 Im assuming this is a script added to a pivot? I tried to look up how global variables are used in LE3 but I couldnt find much. Quote My Games: Nightmare Prism:::WolfTale:::Dungeon Creeper:::Despair of Ordinary Men:::Piano Simulator 2016:::House (W.I.P) Link to comment Share on other sites More sharing options...
josk Posted November 9, 2015 Share Posted November 9, 2015 Near the top of Main.lua just put your global variable. HitPoints = 100 1 Quote Elite Cobra Squad Link to comment Share on other sites More sharing options...
Rick Posted November 9, 2015 Share Posted November 9, 2015 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. 2 Quote Link to comment Share on other sites More sharing options...
Angelwolf Posted November 9, 2015 Author Share Posted November 9, 2015 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? Quote My Games: Nightmare Prism:::WolfTale:::Dungeon Creeper:::Despair of Ordinary Men:::Piano Simulator 2016:::House (W.I.P) Link to comment Share on other sites More sharing options...
Wedmer Posted November 9, 2015 Share Posted November 9, 2015 Save/Load variables to/from file. http://www.lua.org/pil/contents.html#P2 1 Quote Link to comment Share on other sites More sharing options...
Gonan Posted November 10, 2015 Share Posted November 10, 2015 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. 1 Quote Link to comment Share on other sites More sharing options...
Angelwolf Posted November 10, 2015 Author Share Posted November 10, 2015 Thanks for all your replies, very helpful! Quote My Games: Nightmare Prism:::WolfTale:::Dungeon Creeper:::Despair of Ordinary Men:::Piano Simulator 2016:::House (W.I.P) Link to comment Share on other sites More sharing options...
Recommended Posts
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.