The eccoMAGIC Forums
http://forums.eccoMAGIC.com/forum/YaBB.pl
Ecco Tutorials, Tips and How-to Guides >> How do I ..... >> LUA - how to check if the folder content is null?
http://forums.eccoMAGIC.com/forum/YaBB.pl?num=1208921256

Message started by ykorovin on 04/22/08 at 22:27:35

Title: LUA - how to check if the folder content is null?
Post by ykorovin on 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...

Title: Re: LUA - how to check if the folder content is null?
Post by Admin on 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....


;)

Title: Re: LUA - how to check if the folder content is null?
Post by ykorovin on 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?

Title: Re: LUA - how to check if the folder content is null?
Post by Admin on 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...


Title: Re: LUA - how to check if the folder content is null?
Post by ykorovin on 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.

Title: Re: LUA - how to check if the folder content is null?
Post by Admin on 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...


Title: Re: LUA - how to check if the folder content is null?
Post by ykorovin on 04/29/08 at 08:05:56

got it. The doubledot ("..") means text concatenation, and i tried to understand it like logical function.
Thanks!

The eccoMAGIC Forums » Powered by YaBB 2.1!
YaBB © 2000-2005. All Rights Reserved.