I want to output all items (that can be sold in shop) currently in my possession. So I put all items in a table which is before the "while true do" statement.
local itemsTbl = {
[0] = "mushrooms",
[1] = "supermushrooms",
[2] = "ultramushrooms",
[3] = "maxmushrooms",
[4] = "nuts",
[5] = "supernuts",
[6] = "ultranuts",
[7] = "maxnuts",
[8] = "syrups",
[9] = "supersyrups",
[10] = "ultrasyrups",
[11] = "maxsyrups",
[12] = "1ups",
[13] = "1ups DX",
[14] = "goldmushrooms",
[15] = "herbs",
[16] = "redpeppers",
[17] = "greenpeppers",
[18] = "woohoo blends",
[19] = "hoohoo blends",
[20] = "chuckle blends",
[21] = "teehee blends",
[22] = "hoolumbians",
[23] = "chuckoccinos",
[24] = "teeheespressos",
--[32] = "woo beans",
--[33] = "hoo beans",
--[34] = "chuckle beans",
--[35] = "hee beans",
[48] = "bean badges",
[49] = "castle badges",
[50] = "pea badges",
[51] = "bean B. badges",
[52] = "counter badges",
[53] = "charity badges",
[54] = "bros. badges",
[55] = "miracle badges",
[56] = "ohoracle badges",
[57] = "mush badges",
[58] = "mari-lui badges",
[59] = "muscle badges",
[60] = "spiny badges AA",
[61] = "mush badges A",
[62] = "grab badges",
[63] = "mush badges AA",
[64] = "power badges",
[65] = "wonder badges",
[66] = "beauty badges",
[67] = "salvage badges",
[68] = "oh-pah badges",
[69] = "brilliant badges",
[70] = "sarge badges",
[71] = "general badges",
[72] = "tank badges",
[73] = "school emblem",
[74] = "steady badges",
[75] = "oho jee symbol",
[76] = "spiny badges A",
[77] = "bros. lifes",
[78] = "piranha swings",
[79] = "bros. rocks",
[80] = "lucky ribbons",
[81] = "mush badges A",
[82] = "soulful bros.",
[83] = "high-end badges",
[84] = "hand auras",
[85] = "sledge hearts",
[86] = "lucky bros.",
[87] = "bros. respects",
[88] = "bowser fists",
[89] = "bowser fangs",
[90] = "spike badges",
[91] = "chuckola badges",
[104] = "work pants",
[105] = "work jeans",
[106] = "bean pants",
[107] = "blue jeans",
[108] = "parasol pants",
[109] = "hard pants",
[110] = "heart jeans",
[111] = "plaid trousers",
[112] = "#1 trousers",
[113] = "safety slacks",
[114] = "shroom pants",
[115] = "shroom bells",
[116] = "shroom slacks",
[117] = "peachy jeans",
[118] = "mushwin pants",
[119] = "mushluck pants",
[120] = "scandal jeans",
[121] = "street jeans",
[122] = "tropic jeans",
[123] = "hermetic jeans",
[124] = "beanstar pants",
[125] = "peasley slacks",
[126] = "queen B. slacks",
[127] = "B. brand jeans",
[128] = "heart slacks",
[129] = "casual slacks",
[130] = "bubble's gears",
[131] = "chuckola pants",
[132] = "smart pants",
[133] = "school slacks",
[134] = "oho jee wears",
[135] = "oho gears",
[136] = "casual corals",
[137] = "piranha suits",
[138] = "anuboo jeans",
[139] = "ancient pants",
[140] = "heavy slacks",
[141] = "light slacks",
[142] = "harhall's pants",
[143] = "jeanie jeans",
[144] = "wool trousers",
[145] = "random slacks",
[146] = "jeaniest jeans",
[147] = "safe guards",
[148] = "iron pants"
}
key = offset
value = itemname
Mushrooms are stored at 0x48E2
Supermushrooms are stored at 0x48E3
etc.
If I don't have one of an item, the address value will be FF or 00. I can only carry 99 (decimal) of an item at max.
After the "while true do" statement, I run this code in order to output my items:
itempos=0
for offset, itemname in pairs(itemsTbl) do
if memory.read_s8(0x48E2 + offset) > 0 then
gui.text(200,100+itempos, memory.read_s8(0x48E2 + offset).. "x " ..itemname)
itempos = itempos +14
end
end
"itempos" will affect the y-position of each line so I output all items 14 pixels below each time.
If the value at address+offset is greater than 0 then it should output the string and update "itempos".
EDIT:
It seems to somewhat work, but items are out of order...
It outputs in this order:
6x syrups (correct)
1x oho jee wears (I don't have it. address might be wrong...)
1x supersyrups (correct, but should have been listed above oho jee wears...)
1x maxsyrups (correct, ...)
(some badges, they are correct...)
1x work pants (correct)
1x work jeans (correct)
1x maxnuts (should have been listed above syrups...)
So I wonder why items are out of order (please refer to the itemtable above for the correct order - I would appreciate your help with fixing the wrong order). As for oho jee wears and other items that I'm not possessing, I will have to fix wrong addresses or find some other way to account for it.
EDIT:
When starting a new game, it looks nice but the items are still in the wrong order (correct would be: mushrooms, supermushrooms, 1ups, pants)
How can I fix this?
I'm going to be interested in learning about (click or other) events, so I can maybe put these items in an expandable rectangle.