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 


if contains then replace [Help]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Lynxz Gaming
Expert Cheater
Reputation: 4

Joined: 01 Jul 2017
Posts: 208
Location: help

PostPosted: Sun Feb 04, 2018 2:25 am    Post subject: if contains then replace [Help] Reply with quote

how to make if contains "this" then replace "this" to "that"
how?
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sun Feb 04, 2018 4:29 am    Post subject: Re: if contains then replace [Help] Reply with quote

Lynxz Gaming wrote:
how to make if contains "this" then replace "this" to "that"
how?


Code:
local x = 'this'
local y = 'that'
local z = 1

if z == 1 then
  y = 'that'
  x = 'this'
 print(x..' is not '..y..' , right, Lynxz?')
else
 print('I said '..x..' is not '..y..'. Why you asking?')
end

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

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sun Feb 04, 2018 4:56 am    Post subject: Reply with quote

that depends on what "this" is.

if it's just a string then you can use lua's gsub (short for global substitute) function eg.

Code:
-- ex 1
print(string.gsub('this will be replaced', 'this', 'that'))
-- ex 2
local thestring = 'this will be replaced'
print(string.gsub(thestring, 'this', 'that'))
print(thestring:gsub('this', 'that'))
-- ex 3
print(('this this his tis this this that'):gsub('this', 'that'))


see http://lua-users.org/wiki/StringLibraryTutorial for more examples

note that the number that's printed is because gsub also tells you how many times it did the substitution, to avoid that you can assign it to a variable which will only store the first result (the changed string).

If it's a table then you have to loop through the table and change this to that eg.

Code:
inthis = {'a','this',32, 'this', 'this', 42, 'that', {}, 'this'}

for k,v in pairs(inthis) do
  if v == 'this' then
    inthis[k] = 'that'
  end
end
-- print changed table
for k,v in pairs(inthis) do print(v) end


though if you have setup the table so what you want to change is in the index then you can just use table[this] = that eg.
Code:
inthis = {}
inthis.a = 42
inthis.c = 325
inthis.this = 'not that'
inthis.wahtever = {}

if inthis.this then inthis.this = 'that' end
-- print changed table
for k,v in pairs(inthis) do print(v) end


if it's an object from CE (like a stringlist) then you'd have to loop through by the count eg.
Code:
for i=0,thestringlist.Count-1 do
  if thestringlist[i] == 'this' then thestringlist[i] = 'that' end
end
Back to top
View user's profile Send private message
Lynxz Gaming
Expert Cheater
Reputation: 4

Joined: 01 Jul 2017
Posts: 208
Location: help

PostPosted: Mon Feb 05, 2018 6:13 am    Post subject: Reply with quote

what if i want replace a label like
if form.label.contains("this") then
form.label.caption = form.label.replace("this","that")
end

EDIT : nvm i solved it thanks!
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
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