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 


string index

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

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Mon May 23, 2022 12:46 pm    Post subject: string index Reply with quote

So i want to make this thing:
Code:
tp
tp-0
tp-1
tp-2

but it won't instead it giving me
Code:
tp
tp-0
tp-01
tp-010

code is:
Code:
  button[8].OnClick = function(sender)
    local name = inputQuery("Add teleport place","Name your place",nil)

    if type(name) == nil or name == "" then
      name = "undefined-0"
    end

    for i,v in pairs(Trainer.Names.Places) do
      if name == tostring(v) then
        if string.find(v,"%d") then
          name = name..tonumber(string.gsub(v,"%a",""))+1
        elseif not string.find(v,"%d") then
          name = name.."-0"
        end
      end
    end

    Trainer.Places[#Trainer.Places+1] = Vector.new(Car.GetCoord()[1],Car.GetCoord()[2],Car.GetCoord()[3])
    Trainer.Names.Places[#Trainer.Names.Places+1] = name
    comboBoxUpdate3()
  end


typing must be like:
Code:
tp
tp --0
tp --1
tp --2

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1055
Location: 0x90

PostPosted: Mon May 23, 2022 1:34 pm    Post subject: Reply with quote

It looks like you are intentionally adding an extra "0" with the line:
Code:

name = name.."-0"


Try removing the 0.
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Mon May 23, 2022 2:04 pm    Post subject: Reply with quote

did not helped, just shows same string that was typed
_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1249

PostPosted: Mon May 23, 2022 3:51 pm    Post subject: Reply with quote

Code:
local num = 0

  button[8].OnClick = function(sender)
    local name = inputQuery("Add teleport place","Name your place",nil)

    if type(name) == nil or name == "" then
      name = "undefined-0"
    end

    for i,v in pairs(Trainer.Names.Places) do
      if name == tostring(v) then
        if string.find(v,"%d") then
          name = name..tonumber(string.gsub(v,"%a",""))+1
        elseif not string.find(v,"%d") then
          name = name.."-"..num
          num = tonumber(num) + 1
        end
      end
    end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Mon May 23, 2022 3:55 pm    Post subject: Reply with quote

It looks like `Trainer.Names.Places` is a Lua array. You should be using `ipairs` to iterate over it instead of `pairs`.

I don't know what exactly you're trying to do, so I can't offer much help.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Tue May 24, 2022 12:05 am    Post subject: Reply with quote

AylinCE wrote:
Code:
local num = 0

  button[8].OnClick = function(sender)
    local name = inputQuery("Add teleport place","Name your place",nil)

    if type(name) == nil or name == "" then
      name = "undefined-0"
    end

    for i,v in pairs(Trainer.Names.Places) do
      if name == tostring(v) then
        if string.find(v,"%d") then
          name = name..tonumber(string.gsub(v,"%a",""))+1
        elseif not string.find(v,"%d") then
          name = name.."-"..num
          num = tonumber(num) + 1
        end
      end
    end


it works but doesn't index string in a right way
Code:
why
why-0
why-1
test
test-2


need to do smth with num variable

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Wed May 25, 2022 12:16 am    Post subject: Reply with quote

any1?
_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25287
Location: The netherlands

PostPosted: Wed May 25, 2022 2:12 am    Post subject: Reply with quote

don't use pairs, use an indexed table that contains other tables
_________________
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
View user's profile Send private message MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1249

PostPosted: Wed May 25, 2022 10:35 am    Post subject: Reply with quote

Code:
name = "name"
name = name.."-"..0
print(1,name) --> name-0

num=string.match(name,"%d") + 1
name = (name):gsub("%d","")..math.floor(num)
print(2,name) --> name-1

num=string.match(name,"%d") + 1
name = (name):gsub("%d","")..math.floor(num)
print(3,name) --> name-2

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website 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