Welcome, Guest. Please Login or Register.
eccoMAGIC Forums
05/05/24 at 00:11:55
Home Help Search Login Register


Pages: 1
Send Topic Print
LUA - how to check if the folder content is null? (Popularity: 10134 )
cowdad
Contributing  Member
***


I Love Ecco!

Posts: 23
Show the link to this post LUA - how to check if the folder content is null?
04/22/08 at 22:27:35
 
i want to increment folder value by some LUA script
 
newvalue = incrementation + get_folder_value("folder",x[i])
set_folder_value("folder",x[i], newvalue)
 
It works only when get_folder_value("folder",x[i]) is defined. It does not work 1st time, when the old value = null, and the procedure just stops.
 
For a while i used workaround by auto definition folder:=0 for all new items.  
But this way seems not intelligent - i feel there should be an easy way to say something like IF NULL THEN 0 ELSE increment...
Back to top
 
 
  IP Logged
Admin
Administrator
*****


I love Ecco!

Posts: 134
Show the link to this post Re: LUA - how to check if the folder content is null?
Reply #1 - 04/23/08 at 14:35:14
 

 
 
likely are better ways,
 
but I use:
 
Code:
newvalue = incrementation + ("0" .. get_folder_value("folder",x[i]) ) 


 
 
or  
 
Code:
0 +  ("0" .. get_folder_value("folder",x[i])) 


 
 
for number by itself....
 
 
 Wink
Back to top
 
 

The Administrator.
WWW   IP Logged
cowdad
Contributing  Member
***


I Love Ecco!

Posts: 23
Show the link to this post Re: LUA - how to check if the folder content is null?
Reply #2 - 04/23/08 at 14:54:36
 
elegant and simple hack! thank you!
 
while you are online, i'd like to ask a bit another question, where i still want to know a type of value.
 
This is what i want:
   I'd like to set an itemIDkey.
   I select an item, launch LUA,
   if it is a new "clear" item, then set itemIDkey = (max( of all) + 1) ,
   if itemIDkey is already defined, then leave it as is.
 
This is what i have so far:
Code:
x = get_folder_items("itemIDkey") 
max=table.maxn(x) 
m=0
	for i=1,max do 
	m = math.max(m, get_folder_value("itemIDkey",x[i]) )
	end
set_folder_value("itemIDkey",get_select_items()[1],m+1) 
 


 
How can i know if the value is defined without the risk to be thrown out by get_folder_value attempt for undefined value?
Back to top
 
 
  IP Logged
Admin
Administrator
*****


I love Ecco!

Posts: 134
Show the link to this post Re: LUA - how to check if the folder content is null?
Reply #3 - 04/23/08 at 16:24:46
 
I think the issue isn't getting undefined...
 
it's attempting math with a null...
 
 
so you can either test the get return value
 
 
or,
 
create a 'for sure' numeric  [ 0 + ("0" .. get...)]
 
 
 
hope this answers to the Q, you were asking...
 
Back to top
 
 

The Administrator.
WWW   IP Logged
cowdad
Contributing  Member
***


I Love Ecco!

Posts: 23
Show the link to this post Re: LUA - how to check if the folder content is null?
Reply #4 - 04/29/08 at 01:36:38
 
i'm sorry, but the desired string does not work
 
Code:
msgbox("before")
avalue = 0 +  ("0" .. get_folder_value("folder",x[i]))
msgbox("after") 


 
the message "before" appears fine, the message "after" - does not.
Back to top
 
 
  IP Logged
Admin
Administrator
*****


I love Ecco!

Posts: 134
Show the link to this post Re: LUA - how to check if the folder content is null?
Reply #5 - 04/29/08 at 06:43:31
 
the following works for me,  you too ?
 
Code:
avalue = "0" +  ("0" .. get_folder_value("Sample Data",item_id))
msgbox( avalue)
msgbox(0 + ("0".. get_folder_value("Instructions",item_id)) ) 


 
 
keep in mind,  the return value can be null,  but the item_id value CANNOT BE NULL!
 
 
ie. you might have to test that your x[i]  is non-null...
 
Back to top
 
 

The Administrator.
WWW   IP Logged
cowdad
Contributing  Member
***


I Love Ecco!

Posts: 23
Show the link to this post Re: LUA - how to check if the folder content is null?
Reply #6 - 04/29/08 at 08:05:56
 
got it. The doubledot ("..") means text concatenation, and i tried to understand it like logical function.
Thanks!
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print