.getCount() and .Count give null value

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
aSwedishMagyar
Table Makers
Table Makers
Posts: 394
Joined: Mon Jul 06, 2020 3:19 am
Reputation: 455

.getCount() and .Count give null value

Post by aSwedishMagyar »

For reference I am on CE 7.1.
So I'm pretty sure this is just me not knowing how to setup a list properly but when I create an array of strings for example:

Code: Select all

strList = {"String1","String2","String3"}
And before passing the list to a function I get the count:

Code: Select all

--Either this
strNum = strList.Count
--Or this
strNum = strList.getCount()
Those two always return a null so I can't use them to compare against.

My question is: Am I setting up my list incorrectly? If so, what is the correct way to allow use of the Count and getCount() functionality?

User avatar
Cake-san
Table Makers
Table Makers
Posts: 365
Joined: Sun Mar 26, 2017 4:32 pm
Reputation: 500

Re: .getCount() and .Count give null value

Post by Cake-san »

use # eg: #strList

Code: Select all

https://www.lua.org/pil/11.1.html
https://www.lua.org/pil/3.6.html
getCount() & Count is for Stringlist

Code: Select all

https://wiki.cheatengine.org/index.php?title=Lua:Class:Stringlist

eg:
local strList = createStringlist()
strList.text=[[
String1
String2
String3
]]
return strList.Count

aSwedishMagyar
Table Makers
Table Makers
Posts: 394
Joined: Mon Jul 06, 2020 3:19 am
Reputation: 455

Re: .getCount() and .Count give null value

Post by aSwedishMagyar »

Thanks that works now, is there a way to declare it similar to the arrays I have above? Without the need for a newline after each string I mean.

Edit: I just realized I actually don't even need the count since I can just check if the next indexed element is a null and break on that. Either way its good to know you need to createStringList() in order for the .Count and .getCount() to work.

I think I can also use something like this:

Code: Select all

function getCounts(item)
	local index = 1
	while item[index] ~= null do
		index = index + 1
	end
	return index
end
Right?

User avatar
YoucefHam
Cheater
Cheater
Posts: 43
Joined: Sun Jan 21, 2018 10:21 pm
Reputation: 89

Re: .getCount() and .Count give null value

Post by YoucefHam »

Hi, Try to learn from this

Code: Select all

strList = {"String1","String2","String3"}
if strList ~= nil then
  if type(strList) == 'table' then
     print('Table Count : '..#strList)
  else
     print('Var Value : '..strList)
  end
else
  print('nil')
end

Post Reply

Who is online

Users browsing this forum: No registered users