dennis Posted March 5, 2015 Share Posted March 5, 2015 Hi! I'm using rick's SaveLoad.lua to save some basic options. I got the following error: 77 : attempt to index local 'entity' (a nil value)The error occurs in the line 77 which represents: -- be sure to change it's name to what it is in the saved file entity:SetKeyValue("name", entityName) the pivot carry's the same name, the optionsmenu I used isn't in the map which I want to Load the data in. the saved values are: return { -- Table: {1} { ["OptionsMenu"]={2}, }, -- Table: {2} { ["antialias"]=4, ["postprocessing"]=1, }, } and those I'd want to load in another map than I saved the values with. Thanks in common. cheers! Dennis Quote Link to comment Share on other sites More sharing options...
Rick Posted March 5, 2015 Share Posted March 5, 2015 As I recall the entities need to have unique names and if you saved some entity in 1 map and want to load it's data in another I think you'd need to have that entity in the other map named exactly the same. So basically make a pivot named OptionsMenu in your other map and put the loading function that's required and set it up. It won't need to have all the functionality that your real OptionsMenu had in your other map, but it's just a placeholder pivot so you can load the data for it. I hope I'm understanding the issue. Do those scripts even exist on the site anymore? Can't seem to find them. I haven't looked at this in some time so wanted to refresh myself but can't find where it is. Quote Link to comment Share on other sites More sharing options...
dennis Posted March 5, 2015 Author Share Posted March 5, 2015 As I recall the entities need to have unique names and if you saved some entity in 1 map and want to load it's data in another I think you'd need to have that entity in the other map named exactly the same. So basically make a pivot named OptionsMenu in your other map and put the loading function that's required and set it up. It won't need to have all the functionality that your real OptionsMenu had in your other map, but it's just a placeholder pivot so you can load the data for it. I hope I'm understanding the issue. Do those scripts even exist on the site anymore? Can't seem to find them. I haven't looked at this in some time so wanted to refresh myself but can't find where it is. hi rick! thanks for the answer, the pivot is exactly named the same. the map which is used to save the data is called: Menu.map all main menu stuff is enlisted there. the flowgraph shows following: the map where the data needs to be loaded into is called outside_real.map. the data gets triggered by an onsceneloaded.lua and has to be loaded for fpsplayer.lua (for the post effects which is a shader for the camera and also for multisamplemode) so overall: - data gets saved using optionsmenu inside menu.map - data has to be loaded for graphical purpose in outside_real - the loaded data is used by fpsplayer.lua - and gets triggered by onsceneloaded do I also need to post the .map files ? Cheers Quote Link to comment Share on other sites More sharing options...
Rick Posted March 5, 2015 Share Posted March 5, 2015 No I think I get it. So basically you used an entity in menu.map called optionsmenu and you want to load that data inside fpsplayer in outside_real? The system isn't really setup that way. It's setup so that the entity name that saved the data is the same entity name that can load the data. If I recall on load it cycles through all entities getting their name and tries to find that name in the saved file to get the data. So this means in order to load your data inside outside_real: 1) make a pivot and name it OptionsMenu. 2) Attach a script and inside here is where you place your load function that my script will call. Set those loaded values to script variables. 3) If you want to then inform the player of these values when you get them then in fpsplayer.lua add an entity script value (Script.options = nil --entity) and drag the OptionsMenu pivot into this slot. 4) Now in the OptionsMenu script make a script variable of the player (Script.player = nil --entity) and drag the player on it. 5) Create a new function in fpsplayer.lua like (function Script:OptionsLoaded(options) end) 6) In OptionsMenu in the data load function after you've set OptionMenus script variables with what was loaded you can then call this players script since you've linked the player to this script (self.player.script:OptionsLoaded(self.entity). 7) Now inside fpsplayer.lua's OptionsLoaded() you can get that entities values fpsplayer.lua ------------------ Script.options = nil --entity function Script:OptionsLoaded(options) -- now you can read the settings like options.postEffects or something end Options.lua (attached to a pivot in outside_real map) ---------------------------------------------- Script.player = nil --entity -- note I don't 100% remember what the function name is supposed to be called for loading data so it would be whatever it's supposed to be function Script:DataLoad(data) -- read in all the data that was saved self.postEffects = data.postEffects -- tell the player about this data now self.player.script:OptionsLoaded(self) end Basically the name that saved the data is the only name that can load it. So this is a way to do that Quote Link to comment Share on other sites More sharing options...
dennis Posted March 5, 2015 Author Share Posted March 5, 2015 Thanks rick it works !! I had to change self.postfx to postfx Quote Link to comment Share on other sites More sharing options...
Rick Posted March 5, 2015 Share Posted March 5, 2015 ? That's usually a dangerous thing since now it would be global. Can you post what you have because I wouldn't think you'd have to do that. Quote Link to comment Share on other sites More sharing options...
dennis Posted March 5, 2015 Author Share Posted March 5, 2015 I really had to, it is fully working now gheghe but: in the options.lua Script.player = nil --entity function Script:LoadData(data) postfx = data.postprocessing AA = data.antialias self.player.script:OptionsLoaded(self) end and inside fpsplayer: function Script:OptionsLoaded(options) System:Print(postfx) System:Print(AA) if postfx == 1 then self.camera:AddPostEffect("Shaders/PostEffects/EffectClass/08_PP_bloom+godrays.lua") elseif postfx == 0 then System:Print("post effects off") self.camera:ClearPostEffects() end self.camera:SetMultisampleMode(AA) end although the multisample mode has some work in progress but I will fix that Quote Link to comment Share on other sites More sharing options...
Rick Posted March 5, 2015 Share Posted March 5, 2015 You don't want to do what you are doing there. You make those variables global and that's a bad idea. In options.lua change to self.postfx and self.AA then in fpsplayer read them in via options.postfx and options.AA. You see you are passing in the options.lua script to the players OptionsLoaded (self refers to the script itself). So inside OptionsLoaded the parameter variable 'options' now refers to the options.lua script. Quote 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.