Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Concatenation help

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Johnden
Cheater
Reputation: 0

Joined: 30 Jan 2018
Posts: 25

PostPosted: Mon Mar 26, 2018 5:25 am    Post subject: Concatenation help Reply with quote

I have variables
c - text either "Positive" or "Negative"
Total - number

I want the code to write for example:
Code:

CETrainer_Negative5.Visible=true

I have no idea how to do it with concatenation.
I got as far as this:
Code:

a = ("CETrainer_" .. c .. Total .. ".Visible=true")
print(a) -- Used this to check if I got it correct
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Mon Mar 26, 2018 6:51 am    Post subject: Reply with quote

Not really understood what you want, but I try :

Code:
c = '-1'
Total = 300
a = ("CETrainer_" .. c .. Total .. ".Visible=true")
print(a)

c = '-10'
Total = 300
a = ("CETrainer_Negative" .. c .. Total .. ".Visible=true")
print(a)

c = '-10'
c = string.gsub(c,"-","")
Total = 300
a = ("CETrainer_Negative" .. c .. Total .. ".Visible=true")
print(a)

--- result :
CETrainer_-1300.Visible=true
CETrainer_Negative-10300.Visible=true
CETrainer_Negative10300.Visible=true

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Johnden
Cheater
Reputation: 0

Joined: 30 Jan 2018
Posts: 25

PostPosted: Mon Mar 26, 2018 8:53 am    Post subject: Reply with quote

Should've explained it further, sorry. I've created images and renamed them to Positive and Negative

The player can pickup 2 different items, I used variable c,
so it's either c="Positive" or c="Negative"
There is another variable Total that counts how many items you have collected (Positive + Negative)

Instead of writing all of them like this:
Code:

CETrainer_Positive1.Visible=true
CETrainer_Negative2.Visible=true
CETrainer_Positive3.Visible=true
CETrainer_Positive4.Visible=true
...

I want to write them with concatenation to make the code compact.
This code didn't seem to work:

Code:

"CETrainer_" .. c .. Total .. ".Visible=true"
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Mon Mar 26, 2018 9:09 am    Post subject: Reply with quote

If it's in the Lua global table then this will work, if not then replace the global table ("_G") with what ever it's stored in.
Code:
_G["CETrainer_" .. c .. Total].Visible = true

Code:
_G["CETrainer_" .. c .. Total]["Visible"] = true

Code:
if SomeForm["SomeControl" .. c .. Total] ~= nil then
    SomeForm["SomeControl" .. c .. Total].Visible = true
end


The thing to know is that; all objects are tables in Lua, and with the "[]" brackets you can index with a number or a string.

_________________
Back to top
View user's profile Send private message Visit poster's website
Johnden
Cheater
Reputation: 0

Joined: 30 Jan 2018
Posts: 25

PostPosted: Mon Mar 26, 2018 12:12 pm    Post subject: Reply with quote

First code worked for me, thanks Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites