|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Mon Jan 26, 2015 5:11 pm Post subject: Issue assign values to an object. |
|
|
I'm trying to assign values to an object, but if I assign number, it'll convert to string, any idea why?
Code: | foo = {foo = {}};
local index = #foo.foo+1
local t = foo.foo;
t[index] = createForm();
t[index].asd = 100;
print(type(t[index].asd)) -- string.
foo.foo[1].bsd = 100;
print(type(foo.foo[1].bsd)) -- string.
print(type(foo.foo[1].height)) -- number. |
_________________
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Mon Jan 26, 2015 6:30 pm Post subject: |
|
|
Form object doesn't have "asd" property.
Solution:
Code: | createRef(...): integer - Returns an integer reference that you can use with getRef. Useful for objects that can only store integers and need to reference lua objects. (Component.Tag...)
getRef(integer): ... - Returns whatever the reference points out
destroyRef(integer) - Removes the reference |
Example:
Code: | foo = {foo = {}}
index = #foo.foo+1
t = foo.foo
t[index] = createForm()
t[index].Tag = createRef( { mytextproperty='yolo', myintegerproperty=15001} )
print( type( getRef(foo.foo[1].Tag).mytextproperty ) ) -- string.
print( type( getRef(foo.foo[1].Tag).myintegerproperty ) ) -- number.
-- add another property
getRef(foo.foo[1].Tag).anotherproperty = 'YES !'
print( type( getRef(foo.foo[1].Tag).anotherproperty ) ) -- string.
print( getRef(foo.foo[1].Tag).anotherproperty ) -- YES !.
|
_________________
Last edited by mgr.inz.Player on Mon Jan 26, 2015 6:58 pm; edited 1 time in total |
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Mon Jan 26, 2015 6:33 pm Post subject: |
|
|
try using tonumber
but keep in mind that these tags won't be part of the object, but only part of the current variable referencing the object. events called by this object will pass it an object without those tags
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Mon Jan 26, 2015 7:47 pm Post subject: |
|
|
tonumber converts the values to a number, but those tags remain string.
(must use tonumber for compare).
And yes I know object the tags will not pass with the object (I'm accessing it via table).
But I wonder why number is being converted to string, without any way force it remain as a number.
_________________
|
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Mon Jan 26, 2015 8:59 pm Post subject: |
|
|
Try wrap the object (eg.control) with a table.
Code: | function wrap(o, ot)
local w,mt = ot or {},{}
mt.wrapped = o
mt.__index = function(t,k)
local b = mt.wrapped[k]
if type(b) == 'boolean' or b then return b end
return rawget(t,k)
end
mt.__newindex = function(t,k,v)
local b = mt.wrapped[k]
if type(b) == 'boolean' or b then mt.wrapped[k] = v else rawset(t,k,v) end
return v
end
mt.__call = function() return mt.wrapped end -- return original object
return setmetatable(w,mt)
end
-- test
local t = wrap(createForm(), {1,2,3,5})
t.asd = 111;
print(type(t.asd),t.asd) -- string --> number, 100
print(type(t.Height),t.Height) -- number, 240 - default
t.Height=100
t.Width=100
print(type(t.Height),t.Height) -- number, 100 - new set
for k,v in pairs(t) do print(k,tostring(v)) end -- table only property
local l = getPropertyList(t()) -- t() to get origianl object
if l ~= nil then
local s = {}
for i=0,l.Count-1 do s[1+#s]=l[i].."-"..tostring(t[l[i]]) end
print(table.concat(s," \n"))
l.destroy()
end
print(t.ClassName)
t.destroy()
print(t.asd)
print(t.ClassName, '<-- garbage after destroyed') |
|
|
Back to top |
|
|
|
|
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
|
|