Jump to content




Draw image from variables SOLVED!


7 replies to this topic

#1 danielsv03

  • Members
  • 66 posts
  • LocationMinecraft world

Posted 20 April 2017 - 04:17 PM

Hello so i'm trying to load a image but when i want to use x and y coordination's instead of numbers i want to use the variables from my tables like this.. ps image is correct because when i do paintutils.drawImage(lua_icon,1, 1) it works instead of pos and ypos


function load(name)
local file = fs.open(name,"r")
local data = file.readAll()
file.close()
return textutils.unserialize(data)
end
tabl = load("root/system/configs/AppPos.conf")
--root/system/configs/AppPos.conf
print(tabl)
print(tabl.ypos)
print(tabl.xpos)
lua_icon = paintutils.loadImage("root/system/Apps/Lau_Shell/lua_shell.icon")
paintutils.drawImage(lua_icon, tabl.ypos, tabl.xpos)

Table

{
  app = "Lua_Shell",
  xpos = "10",
  ypos = "5",
}

Edited by danielsv03, 20 April 2017 - 05:35 PM.


#2 danielsv03

  • Members
  • 66 posts
  • LocationMinecraft world

Posted 20 April 2017 - 04:23 PM

Forgot to mention it outputs:
5
10
expected image, x, y

#3 Exerro

  • Members
  • 801 posts

Posted 20 April 2017 - 04:44 PM

Your x and y positions are strings, not numbers. Remove the speech marks in the table:
{
  app = "Lua_Shell",
  xpos = 10,
  ypos = 5,
}

I think you've mis-spelt 'Lua' in the image path, too ("root/system/Apps/Lau_Shell/lua_shell.icon").

Note, coordinates are generally (x, y) not (y, x), that is, how far across by how far down. It's just confusing to everyone to swap the names like you've done.

#4 danielsv03

  • Members
  • 66 posts
  • LocationMinecraft world

Posted 20 April 2017 - 05:32 PM

View PostExerro, on 20 April 2017 - 04:44 PM, said:

Your x and y positions are strings, not numbers. Remove the speech marks in the table:
{
  app = "Lua_Shell",
  xpos = 10,
  ypos = 5,
}

I think you've mis-spelt 'Lua' in the image path, too ("root/system/Apps/Lau_Shell/lua_shell.icon").

Note, coordinates are generally (x, y) not (y, x), that is, how far across by how far down. It's just confusing to everyone to swap the names like you've done.


Thanks it worked BUT when i use the table or do something with it then it automaitcly adds the "" back how can i prevent this?

#5 Exerro

  • Members
  • 801 posts

Posted 20 April 2017 - 05:58 PM

I'll need to see how you're saving the table and where you're getting the coords from. Most likely is that you're doing table.xpos = read() somewhere? If you change that to table.xpos = tonumber( read() ) it should fix it. If it doesn't, post the code where you're updating the values in the table and when you're saving it and I can help more.

#6 danielsv03

  • Members
  • 66 posts
  • LocationMinecraft world

Posted 20 April 2017 - 06:14 PM

The thing is i'm not saving the code i'm just loading it btw here all the code from the file that is doing that
tabl = load("root/system/configs/AppPos.conf")
--root/system/configs/AppPos.conf
print(tabl)
print(tabl.ypos)
print(tabl.xpos)
lua_icon = paintutils.loadImage("root/system/Apps/Lau_Shell/lua_shell.icon")
paintutils.drawImage(lua_icon, tabl.ypos, tabl.xpos)

tab = {app = "Lua_Shell", xpos = "10", ypos = "5"}
save(tab, "root/system/configs/AppPos.conf")


#7 danielsv03

  • Members
  • 66 posts
  • LocationMinecraft world

Posted 20 April 2017 - 06:29 PM

View PostExerro, on 20 April 2017 - 05:58 PM, said:

I'll need to see how you're saving the table and where you're getting the coords from. Most likely is that you're doing table.xpos = read() somewhere? If you change that to table.xpos = tonumber( read() ) it should fix it. If it doesn't, post the code where you're updating the values in the table and when you're saving it and I can help more.

The thing is i'm not saving the code i'm just loading it btw here all the code from the file that is doing that
tabl = load("root/system/configs/AppPos.conf")
--root/system/configs/AppPos.conf
print(tabl)
print(tabl.ypos)
print(tabl.xpos)
lua_icon = paintutils.loadImage("root/system/Apps/Lau_Shell/lua_shell.icon")
paintutils.drawImage(lua_icon, tabl.ypos, tabl.xpos)

tab = {app = "Lua_Shell", xpos = "10", ypos = "5"}
save(tab, "root/system/configs/AppPos.conf")

#8 Exerro

  • Members
  • 801 posts

Posted 20 April 2017 - 09:54 PM

Ehh, look at the last two lines again. Not saving it, you say? Remove the speech marks around the numbers and it'll work fine.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users