Discord
Login
Community
DARK THEME

accidentally changing the preset for classes?

im working on a game in which i need descriptions. in order to fit them into text boxes, im splitting the given text and and putting into a list. it failed so i messed around to figure out how but in the process, i accidentally made my class preset change everytime i make one.

  new_upgrade("Paint Mixing",0,0,"base",[],"visible",1,0,"Combine towers to create new towers.","hex",48,48)
  new_upgrade("Green",30,16,"green",[tree[0]],"invisible",1,15,"12345678910abcdefghijklmopqrstvwxyz")
  new_upgrade("Orange",-30,16,"orange",[tree[0]],"invisible",1,15,"12345678910abcdefghijklmopqrstvwxyz")
  new_upgrade("Purple",0,-30,"purple",[tree[0]],"invisible",1,15,"12345678910abcdefghijklmopqrstvwxyz")


upgrades = class
  x = 0
  y = 0
  width = 24
  height = 24
  sprite = 0
  parents = []
  state = "invisible"
  levels = 0
  max_levels = 1
  shape = "square"
  name = 0
  price = 0
  lore = []
end

new_upgrade = function(name,x,y,sprite,parents,state,max_levels,price,lores,shape,width,height)
  local upgradable = new upgrades
  print(upgradable.lore)
  upgradable.name = name
  upgradable.x = x
  upgradable.y = y
  upgradable.sprite = sprite
  upgradable.parents = parents
  upgradable.state = state
  upgradable.max_levels = max_levels
  upgradable.price = price
  print(name)
  print(upgradable.lore)
  if lores.length > 10 then
    if lores.length > 10 then
      if lores[10] == " " then
        upgradable.lore.push(lores.substring(10))
        lores.replace(lores.substring(0,10),"")
      else
        print(upgradable.lore)
        upgradable.lore.push(lores.substring(9)+"-")
        lores.replace(lores.substring(0,9),"")
      end
    end
  end
  if width > 0 then
    upgradable.width = width
  end
  if height > 0 then
    upgradable.height = height
  end
  if shape != 0 then
    upgradable.shape = shape
  end
  tree.push(upgradable)
  print(tree[0].lore)
end

this is the class and the spawn function for it, as well as everytime i call it. everytime i create a new class even without the function after it is ran, they automatically are created with the "lore" of the previous ones, and the old ones gain the new lore. this is all ran during init(), before any updates or draws

nvm, i fixed it by using a local list instead, then just doing upgradable.lore = list. i guess adding to a list of a class object makes it part of the class preset? i dont know if this is maybe a bug?

Post a reply

Progress

Status

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