Discord
Login
Community
DARK THEME

save level HELP!!!!!!

im making a level editior game: microstudio.io/JensGameStudios/bobmaker

and i want that if you finish a level you can save it and load it another time

You can use json for that ( look File API) or asset manager. Or look project access API. Use what better for your project and for way of making a map.

file >> main

saveMap = function(mapObj)
  print( "Save" )
  storage.set("map Width", mapObj.width )
  storage.set("map Height", mapObj.height )
  storage.set("map block_width", mapObj.block_width )
  storage.set("map block_height", mapObj.block_height )  
  local list = []
  for i = 0 to mapObj.width - 1 by 1
    for j = 0 to mapObj.height - 1 by 1 
      list.push( mapObj.get( i, j ))
    end
  end
  storage.set( "map Array", list)
end
  
  
loadMap = function()
  print( "Load" )
  local width = storage.get("map Width")
  local height = storage.get("map Height")
  local block_width = storage.get("map block_width")
  local block_height = storage.get("map block_height") 
  local data = storage.get("map Array")
  
  local mapObj = new Map(width, height, block_width, block_height )
  print(data)
  for i = 0 to width - 1 by 1
    for j = 0 to height - 1 by 1
      local idx = i * height + j
      mapObj.set(i, j, data[idx])
    end
  end
  
  return mapObj
end

draw = function()
  if playing == true then
    Quick.draw()
    touchKeys.draw()
    ui()
    
 
    if saveButton then 
      saveMap(map.map)
    end

    if loadButton then 

      Quick.remove( map )
      maps[ "load" ] = loadMap()
      map = Quick.addMap( "load",  ......... )
    end

file >> player

ui = function()
  saveButton = IMGUI.button("Save", 150, 80, 40, 20) 
  loadButton = IMGUI.button("Load", 200, 80, 40, 20) 
.......

Thanks!!!!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community