hippokittie Posted December 25, 2014 Share Posted December 25, 2014 Hey so I have been messing around with the map changer that came with leadwerks (copied it and renamed it so I have the original still) to choose between random seed maps (initial starting areas the rest is generated) but when it tried to change maps it crashes or gives me a lua stack overflow issue. Is there something wrong with my code? Here it is. --[[ This script will act as a trigger to change the current map. Place this at the end of your map to make the player progress to the next level. ]]-- Script.mapname={} Script.mapname[0] = "" --string "Map Name" Script.mapname[1] = "" --string "Map Name" Script.mapname[2] = "" --string "Map Name" Script.mapname[3] = "" --string "Map Name" function Script:Start() self.enabled=true math.randomseed(Time:Millisecs()) math.random();math.random();math.random(); self.counter = 0 end function Script:Collision(entity, position, normal, speed) changemapname = math.random(0,3) end function Script:Enable()--in if self.enabled==false then self.enabled=true self:CallOutputs("Enable") end end function Script:Disable()--in if self.enabled then self.enabled=false self:CallOutputs("Disable") end end Quote Will Hall Morphodox Studios Link to comment Share on other sites More sharing options...
beo6 Posted December 26, 2014 Share Posted December 26, 2014 (edited) I haven't tried it but i think it is not possible to make attributes like this directly into a lua table. you might need to make normal variables instead and add these later to your lua table. (all code untested) Script.mapfile0 = ""--path "Map File 0" "Map file:map" Script.mapfile1 = ""--path "Map File 1" "Map file:map" Script.mapfile2 = ""--path "Map File 2" "Map file:map" Script.mapfile3 = ""--path "Map File 3" "Map file:map" and then inside Script:Start() local maxMaps = 3 self.mapname = {} for n=0,maxMaps do if _G["mapfile"..tostring(n)] ~= "" then mapname[n] = _G["mapfile"..tostring(n)] end end EDIT: forget the last code since that only works for global variables. But i guess you get what i mean. Edited December 26, 2014 by beo6 Quote Link to comment Share on other sites More sharing options...
hippokittie Posted December 26, 2014 Author Share Posted December 26, 2014 I haven't tried it but i think it is not possible to make attributes like this directly into a lua table. you might need to make normal variables instead and add these later to your lua table. (all code untested) Script.mapfile0 = ""--path "Map File 0" "Map file:map" Script.mapfile1 = ""--path "Map File 1" "Map file:map" Script.mapfile2 = ""--path "Map File 2" "Map file:map" Script.mapfile3 = ""--path "Map File 3" "Map file:map" and then inside Script:Start() local maxMaps = 3 self.mapname = {} for n=0,maxMaps do if _G["mapfile"..tostring(n)] ~= "" then mapname[n] = _G["mapfile"..tostring(n)] end end EDIT: forget the last code since that only works for global variables. But i guess you get what i mean. so I would change the map selection back to the default? then call the table later? or would I set it as you have above and put the name of the map directly in the quotes? I have a similar code (what I took the random from) for random spawns. I adjusted it with the trigger touch to make this. Quote Will Hall Morphodox Studios Link to comment Share on other sites More sharing options...
Guppy Posted December 26, 2014 Share Posted December 26, 2014 http://www.lua.org/pil/11.1.html Quote System: Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k Link to comment Share on other sites More sharing options...
beo6 Posted December 26, 2014 Share Posted December 26, 2014 i don't know what you mean with put the name of the map directly in the quotes? but after you assigned the maps each into its own variable you can assign these into a table. Here is a working script now. --[[ This script will act as a trigger to change the current map. Place this at the end of your map to make the player progress to the next level. ]]-- Script.mapfile0 = ""--path "Map File 0" "Map file:map" Script.mapfile1 = ""--path "Map File 1" "Map file:map" Script.mapfile2 = ""--path "Map File 2" "Map file:map" Script.mapfile3 = ""--path "Map File 3" "Map file:map" function Script:Start() self.mapname = {} math.randomseed(Time:Millisecs()) if self.mapfile0 ~= "" then self.mapname[1] = self.mapfile0 end if self.mapfile1 ~= "" then self.mapname[2] = self.mapfile1 end if self.mapfile2 ~= "" then self.mapname[3] = self.mapfile2 end if self.mapfile3 ~= "" then self.mapname[4] = self.mapfile3 end end function Script:Collision(entity, position, normal, speed) local changeMapNr = math.random(1,#self.mapname) if changemapname == nil then --fix for changemap part in default App.lua local changeToMapFileFix = string.gsub(self.mapname[changeMapNr], ".map$","") changeToMapFileFix = string.gsub(changeToMapFileFix, "^.*/","") changemapname = changeToMapFileFix end end However i would change the changemap part in the App.lua to accept not only a mapname but the path including the file extension. Then you could remove the "fix for changemap part in default App.lua" part and still have the file selectors in the editor. Quote Link to comment Share on other sites More sharing options...
hippokittie Posted December 26, 2014 Author Share Posted December 26, 2014 Thank beo6 that's helpful. I am going to be adding in a bunch of seeds, so this will help a lot . I was told not to mess with the app.lua though, so would it be fine just to tweek this code a bit? I am going to be adding in a load screen image as well so it doesn't look frozen Quote Will Hall Morphodox Studios Link to comment Share on other sites More sharing options...
beo6 Posted December 27, 2014 Share Posted December 27, 2014 You can tweak the code how you want. Another small thing you should add is a check which entity type collides with it. Currently everything that collides with the trigger will start the mapchange. But you will most likely only want to have the player change the map. Quote Link to comment Share on other sites More sharing options...
hippokittie Posted December 28, 2014 Author Share Posted December 28, 2014 Yeah that was one of the tweaks I went for Quote Will Hall Morphodox Studios 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.