Posted: Thu Jan 13, 2022 10:32 am Post subject: [Q] Complex Lua question |P to Unicode String to P on Button
Hello everyone,
I wanted to get more into assembler and LUA so I decided to take one of my favorite games apart, so far successfully, learning a lot in the meantime.
However, I have run into a wall that I can't solve yet.
What I have:
Level 2 pointer to X
Level 2 pointer to Y
Level 4 pointer to X2
Level 4 pointer to Y2
What I want:
At the press of a button, I want to read from X2, Y2 and put the value into the memory of X, Y respectively.
The issue:
X and Y are floats
X2 and Y2 are Unicode String[5] and need to be parsed.
I have no clue how to do all that at the press of a button
Nice to have:
Freezing X and Y via LUA as well instead of over Toggle Freeze.
Posted: Sat Jan 15, 2022 7:18 am Post subject: Re: [Q] Complex Lua question |P to Unicode String to P on Bu
Gravitary wrote:
Hello everyone,
I wanted to get more into assembler and LUA so I decided to take one of my favorite games apart, so far successfully, learning a lot in the meantime.
However, I have run into a wall that I can't solve yet.
What I have:
Level 2 pointer to X
Level 2 pointer to Y
Level 4 pointer to X2
Level 4 pointer to Y2
What I want:
At the press of a button, I want to read from X2, Y2 and put the value into the memory of X, Y respectively.
The issue:
X and Y are floats
X2 and Y2 are Unicode String[5] and need to be parsed.
I have no clue how to do all that at the press of a button
Nice to have:
Freezing X and Y via LUA as well instead of over Toggle Freeze.
Any help is appreciated.
Best regards.
You can use a timer to set the value of X and Y via Lua. As for the Unicode String you could use the Lua function tonumber(variable).
Code:
local x = "500.00"
-- print is to show the casting although visibly, they look the same.
print(tonumber(x))
For a timer you can do something like this:
Code:
local mytimer = createTimer(getMainForm())
mytimer.Interval = 1000 -- Interval is in milliseconds
mytimer.OnTimer = function()
local al = getAddressList()
local X = al.getMemoryRecordByDescription("Entry in table that has X description")
local Y = al.getMemoryRecordByDescription("Entry in table that has Y description")
local X2 = al.getMemoryRecordByDescription("Entry in table that has X2 description")
local Y2 = al.getMemoryRecordByDescription("Entry in table that has Y2 description")
-- Double-check that the entries exist
if X ~= nil and Y ~= nil and X2 ~= nil and Y2 ~= nil then
X.Value = tonumber(X2)
Y.Value = tonumber(Y2)
else
-- If the entries don't exist, we don't want the timer to continue running so we kill it
mytimer.destroy()
mytimer = nil
end
end
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum