Page 1 of 1

.getCount() and .Count give null value

Posted: Fri Oct 23, 2020 11:26 pm
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?

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

Posted: Fri Oct 23, 2020 11:54 pm
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

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

Posted: Sat Oct 24, 2020 12:32 am
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?

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

Posted: Sun Jan 03, 2021 11:18 am
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