63 posts
Posted 08 September 2017 - 09:03 PM
The next few weeks, i am working on a new Operating System. I need a desktop where you can add a icon, with a startfile. So you can start the file when you click on. Is there a sort of API that i can use for this? So i can know:
Where the icon is
What program it is
-DubbelSoftware
797 posts
Posted 08 September 2017 - 09:15 PM
The API you're after is native Lua tables. Just keep a list of objects like {x, y, file [, icon]}. You can iterate through it for click detection and drawing.
63 posts
Posted 09 September 2017 - 08:08 PM
The API you're after is native Lua tables. Just keep a list of objects like {x, y, file [, icon]}. You can iterate through it for click detection and drawing.
I am currently making this, and trying this. But when loading the logo and store it in the table. It wil not loadable. Is this normal?
797 posts
Posted 09 September 2017 - 08:20 PM
Sorry, I don't know what you mean. Do you mean loading something from a file? An icon, or the list of shortcuts?
If you mean the icon, it depends on the file format you're using. If you're using paint to draw the icon, it'll be paintutils.loadImage(). Otherwise, use a loading function for the file format you use.
If you mean the list of shortcuts, you can use textutils.[un]serialize() to load and save the list.
63 posts
Posted 09 September 2017 - 08:23 PM
Sorry, I don't know what you mean. Do you mean loading something from a file? An icon, or the list of shortcuts?
If you mean the icon, it depends on the file format you're using. If you're using paint to draw the icon, it'll be paintutils.loadImage(). Otherwise, use a loading function for the file format you use.
If you mean the list of shortcuts, you can use textutils.[un]serialize() to load and save the list.
I am storing a path (in string) to the table. But when i want to load if from the table with:
paintutils.drawImage(paintutils.loadImage(iconData[i]), tonumber(iconData["1_x"]), tonumber(iconData["1_y"]))
it doesnt load, and says unexpected path. By the way the 1_x and 1_y are correctly. These are loaded with a function.
Edited on 09 September 2017 - 06:23 PM
3057 posts
Location
United States of America
Posted 09 September 2017 - 10:27 PM
Without knowing what exactly is in iconData, it's very difficult to debug. May I suggest adding some print statements? If the UI drawing does not allow you to view the results, I suggest writing the data to a file.
63 posts
Posted 10 September 2017 - 08:02 AM
UPDATE:
I have found out why it was not working.
Edited on 10 September 2017 - 06:12 AM
2427 posts
Location
UK
Posted 10 September 2017 - 02:54 PM
UPDATE:
I have found out why it was not working.
Please share so that others who find this post with simular issues have the solution.
467 posts
Location
Van Diemen's Land
Posted 11 September 2017 - 01:03 AM
UPDATE:
I have found out why it was not working.
Please share so that others who find this post with simular issues have the solution.
IF anyone does ["1_y"] instead of [1]["y"]..
63 posts
Posted 11 September 2017 - 04:13 PM
UPDATE:
I have found out why it was not working.
Please share so that others who find this post with simular issues have the solution.
I wil release the code soon in this topic when my OS is finished and released.
UPDATE:
I have found out why it was not working.
Please share so that others who find this post with simular issues have the solution.
IF anyone does ["1_y"] instead of [1]["y"]..
I am not that good at creating tables, i also dont know much about tables. I only know how to use them like that.
Also, this wil be changed when the OS is stable.
-DubbelSoftware
467 posts
Location
Van Diemen's Land
Posted 12 September 2017 - 02:03 AM
I am not that good at creating tables, i also dont know much about tables. I only know how to use them like that.
Also, this wil be changed when the OS is stable.
-DubbelSoftware
You can do some pretty powerful things with tables.
Look at this:
local testTable = {
[1] = {
test = "this is a test"
},
["lollies"] = {
test = "yummy"
}
}
local testString = "lollies"
print(testTable[1].test) -- output: "this is a test"
print(testTable[1]["test"]) -- output: "this is a test"
print(testTable.lollies.test) -- output: "yummy"
print(testTable["lollies"].test) -- output: "yummy"
print(testTable["lollies"]["test"]) -- output: "yummy"
print(testTable.lollies["test"]) -- output: "yummy"
print(testTable[testString].test) -- output: "yummy"
print(testTable.testString.test) -- output: attempt to index (error)
for k,v in pairs(testTable) do
print(k)
print(v.test)
end
-- output:
-- 1
-- "this is a test"
-- "lollies"
-- "yummy"
Edited on 12 September 2017 - 12:04 AM