|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
DTeCH Newbie cheater Reputation: 0
Joined: 19 Jul 2013 Posts: 23 Location: Cayman Islands
|
Posted: Mon Sep 23, 2013 7:16 pm Post subject: How to access (read/write) to variable from a function? |
|
|
Hey guys
I am writing another cheat trainer in Lua script with cheat engine's Generate trainer from table, & manually create trainer... instead of the usual trainer maker thingy.
My troubles seem to be with a variable that is written at the beginning of the Lua script that is not in a function. It has a value of "TEST", but when I access it from a function (button click), I can read "TEST" from the variable, but not write, or otherwise alter it.
Is there some way to set it up so it's accessible?
Maybe there's a way to call it properly so it can be edited?
I tried it with another variable that has a numeric value also at the beginning of the script outside of any function, & i can alter it as expected, so I'm confused.
Any help is awesome as usual
EDIT:
Code: | --TRAINERGENERATORSTART--
--This is autogenerated code. Changing code in this block will
--get erased and rewritten if you regenerate the trainer code
--Uncomment the following line if this is a Cheat Table format trainer and you don't want CE to show (Tip, save as .CETRAINER alternatively)
--hideAllCEWindows()
RequiredCEVersion=6.3
if (getCEVersion==nil) or (getCEVersion()<RequiredCEVersion) then
messageDialog('Please install Cheat Engine '..RequiredCEVersion, mtError, mbOK)
closeCE()
end
TestVarNum = 1
TestVarString = "TEST"
function ButtonClick(sender)
CBO = component_findComponentByName(CETrainer,'CEComboBox1')
TestVarNum = getProperty(CBO,'ItemIndex')
messageDialog( "The combobox index is " .. TestVarNum .. ".", 4, 2 );
TestVarString = "AnotherTEST"
messageDialog( "The TestVarString value is " .. TestVarString .. ".", 4, 2 );
end
|
The above code is basically equivalent to my problem... TestVarNum works fine, but TestVarString is still set to what is was originally set to at the beginning of the script. Doesn't change.
I guess what I'm asking is, is it possible to alter a global variable's value from a function's local code block? If so, example?
_________________
Hitler... When all else fails, you'll be in the right state of mind. Jesus Saves. |
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Mon Sep 23, 2013 8:38 pm Post subject: |
|
|
Code: | TestVarNum = -1 -- The default is -1.
TestVarString = "TEST"
function ButtonClick(sender)
-- This is just extra work...
--[[
CBO = component_findComponentByName(CETrainer,'CEComboBox1')
TestVarNum = getProperty(CBO,'ItemIndex')
--]]
TestVarNum = CETrainer.CEComboBox1.ItemIndex -- Returns combo box index.
messageDialog( "The combobox index is " .. TestVarNum .. ".", 4, 2 );
TestVarString = "AnotherTEST"
messageDialog( "The TestVarString value is " .. TestVarString .. ".", 4, 2 );
end |
Example of local and global.
Code: | function example1()
local code = 1
print(code); --> 1
end
function example2()
code = 2
print(code); --> 2
end
example1()
print(type(code)) --> nil because it was local
example2()
print(type(code)) --> 2, it's global
|
You shouldn't have any problems changing the var value.
_________________
|
|
Back to top |
|
|
DTeCH Newbie cheater Reputation: 0
Joined: 19 Jul 2013 Posts: 23 Location: Cayman Islands
|
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Mon Sep 23, 2013 9:58 pm Post subject: |
|
|
Code: | function example1()
local code = "1"
print(code); --> 1 (String)
end
function example2()
code = "2"
print(code); --> 2 (String)
end
example1()
print(type(code)) --> nil because it was local string
example2()
print(type(code)) --> 2 (String), it's global |
There's no difference between "" '' and [[ ]]
But for example to show this message
Code: | print("Hey there it's a string with ' char"); |
using ' instead of " will break it (because the it's word has the ').
Vice versa..
Code: | print('One day a guy said "LOL"'); |
using " here will break it too.
To avoid these two. just use this.
Code: | print([[Look I can do this " and that ' togther '' "" """ '' '' '' ']]); |
But it does not parse for example new lines (\n) like other does.
_________________
|
|
Back to top |
|
|
DTeCH Newbie cheater Reputation: 0
Joined: 19 Jul 2013 Posts: 23 Location: Cayman Islands
|
Posted: Mon Sep 23, 2013 11:43 pm Post subject: |
|
|
Well... I looked it over, & have to say that it's not being overwritten in any way. I have been eye-balling the code line by line from 8 AM this morning, & it's 11:30 PM. There is NO reason for this other than possibly corruption of cheat engine somehow in memory, or in it's DLLs. I really don't want to re-install, or whatever only to find out that there's a simple thing I've overlooked.
Here is a simple test i did, & it's still not working:
Code: | BUG = "nothing"
THIS = 2 --Let's say THIS = 2
function bugTest(sender)
if THIS == '1' then
BUG = "somestring" --Works if this is the first instance of BUG
end
if THIS == '2' then
BUG = "something else"
end
messageDialog( "The chosen broser is " .. BUG .. ".", 4, 2 );
--BUG is still = "nothing" :(
end |
_________________
Hitler... When all else fails, you'll be in the right state of mind. Jesus Saves. |
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Tue Sep 24, 2013 1:07 am Post subject: |
|
|
Code: | BUG = "nothing" --> String
THIS = 2 --> Number
function bugTest(sender)
-- if THIS == '1' then --> Compare number with string
if (THIS == 1) then -- If This equals to 1 then it'll define BUG as "somestring" and continue to the next if, if not, will continue to the next if without touching BUG.
BUG = "somestring" -- Changes BUG
print(BUG);
end
-- if THIS == '2' then --> Compare number with string
if (THIS == 2) then -- If This equals to 2 then it'll define BUG as "somestring" and continue to the next if, if not, will continue to the next if without touching BUG.
BUG = "something else" -- Changes BUG
print(BUG);
end
messageDialog( "The chosen broser is " .. BUG .. ".", 4, 2 );
end
|
_________________
|
|
Back to top |
|
|
DTeCH Newbie cheater Reputation: 0
Joined: 19 Jul 2013 Posts: 23 Location: Cayman Islands
|
|
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
|
|