I have run into some kind of problem/bug with lua, I think...
I have a script that saves stats and properties of Mario and Luigi into the objects Mario and Luigi (it does this on start-up and every frame inside a while true do loop). And I have objects MarioBefore and LuigiBefore that save the values from the frame before.
local Mario = {
Health = memory.read_s16_le(0x4866),
HealthMax = memory.read_s16_le(0x486A),
BP = memory.read_s16_le(0x486c),
BPMax = memory.read_s16_le(0x4870),
Pow = memory.read_s16_le(0x4874),
Def = memory.read_s16_le(0x487c),
Speed = memory.read_s16_le(0x4878),
Hige = memory.read_s16_le(0x4880),
Level = memory.read_s8(0x4888),
Experience = memory.read_s16_le(0x485c),
X = memory.read_s24_le(0x6c14),
Y = memory.read_s24_le(0x6c18),
Z = memory.read_s24_le(0x6c1B),
Altitude = memory.read_s24_le(0x6c20)
}
local Luigi = {
Health = memory.read_s16_le(0x48a2),
HealthMax = memory.read_s16_le(0x48a6),
BP = memory.read_s16_le(0x48a8),
BPMax = memory.read_s16_le(0x48ac),
Pow = memory.read_s16_le(0x48b0),
Def = memory.read_s16_le(0x48b8),
Speed = memory.read_s16_le(0x48b4),
Hige = memory.read_s16_le(0x48bc),
Level = memory.read_s8(0x48c4),
Experience = memory.read_s16_le(0x4898),
X = memory.read_s24_le(0x6fb0),
Y = memory.read_s24_le(0x6fb4),
Z = memory.read_s24_le(0x6fb8),
Altitude = memory.read_s24_le(0x6fbB)
}
local MarioBefore = Mario
local LuigiBefore = Luigi
...
while true do
local Mario = {
Health = memory.read_s16_le(0x4866),
HealthMax = memory.read_s16_le(0x486A),
BP = memory.read_s16_le(0x486c),
BPMax = memory.read_s16_le(0x4870),
Pow = memory.read_s16_le(0x4874),
Def = memory.read_s16_le(0x487c),
Speed = memory.read_s16_le(0x4878),
Hige = memory.read_s16_le(0x4880),
Level = memory.read_s8(0x4888),
Experience = memory.read_s16_le(0x485c),
X = memory.read_s24_le(0x6c14),
Y = memory.read_s24_le(0x6c18),
Z = memory.read_s24_le(0x6c1B),
Altitude = memory.read_s24_le(0x6c20)
}
local Luigi = {
Health = memory.read_s16_le(0x48a2),
HealthMax = memory.read_s16_le(0x48a6),
BP = memory.read_s16_le(0x48a8),
BPMax = memory.read_s16_le(0x48ac),
Pow = memory.read_s16_le(0x48b0),
Def = memory.read_s16_le(0x48b8),
Speed = memory.read_s16_le(0x48b4),
Hige = memory.read_s16_le(0x48bc),
Level = memory.read_s8(0x48c4),
Experience = memory.read_s16_le(0x4898),
X = memory.read_s24_le(0x6fb0),
Y = memory.read_s24_le(0x6fb4),
Z = memory.read_s24_le(0x6fb8),
Altitude = memory.read_s24_le(0x6fbB)
}
...
code that compares them
...
local MarioBefore = Mario
local LuigiBefore = Luigi
When I start the script, MarioBefore and LuigiBefore seem to have wrong values though. Log of MarioBefore:
Notice that the very first frame has wrong values, but all subsequent frames are correct.
"Altitude": "1316368"
"BP": "2824"
"BPMax": "-31794"
"Def": "-5757"
"Experience": "-5085"
"Health": "-1533"
"HealthMax": "-5880"
"Hige": "2060"
"Level": "-64"
"Pow": "1359"
"Speed": "-13821"
"X": "1451906"
"Y": "-8248820"
"Z": "2760235"
"Altitude": "0"
"BP": "22"
"BPMax": "22"
"Def": "23"
"Experience": "444"
"Health": "5"
"HealthMax": "18"
"Hige": "13"
"Level": "7"
"Pow": "54"
"Speed": "27"
"X": "136448"
"Y": "151296"
"Z": "0"
"Altitude": "0"
"BP": "22"
"BPMax": "22"
"Def": "23"
"Experience": "444"
"Health": "5"
"HealthMax": "18"
"Hige": "13"
"Level": "7"
"Pow": "54"
"Speed": "27"
"X": "136448"
"Y": "151296"
"Z": "0"
"Altitude": "0"
"BP": "22"
"BPMax": "22"
"Def": "23"
"Experience": "444"
"Health": "5"
"HealthMax": "18"
"Hige": "13"
"Level": "7"
"Pow": "54"
"Speed": "27"
"X": "136448"
"Y": "151296"
"Z": "0"
How come MarioBefore has such wrong values even when I made sure to run MarioBefore=Mario before it even enters while true do territory?