Empty parameter in function

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Empty parameter in function

Post by croivo » Fri Apr 03, 2015 9:58 pm

I have this function:

Code: Select all

function play item1, item2, item3, item4, item5, item6

repeat with numberVar = 1 to 6
      put ("item" & numberVar) into theNameOfHolder
      
      if theNameOfHolder is empty then
         answer ("Variable " & theNameOfHolder & " is empty!")
      end if
      
   end repeat

end play
Very often I won't call all 6 parameters... So I need to check somehow if some 'item' variables are empty or not.
I tried with this if statemet to check if it's empty, but it's not working... Any ides?

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Empty parameter in function

Post by SparkOut » Fri Apr 03, 2015 10:12 pm

Quick answer: see "value" in the dictionary.

croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: Empty parameter in function

Post by croivo » Fri Apr 03, 2015 10:57 pm

Thanks :D

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Empty parameter in function

Post by Klaus » Fri Apr 03, 2015 11:26 pm

Hi croivo,

"play" is a reserved word in LC, so to avoid possible inconvenience
you really should rename your function! 8)


Best

Klaus

croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: Empty parameter in function

Post by croivo » Fri Apr 03, 2015 11:39 pm

Klaus wrote:Hi croivo,

"play" is a reserved word in LC, so to avoid possible inconvenience
you really should rename your function! 8)


Best

Klaus
Yes yes I know, at the moment of writing I was not thinking about the name too much...

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Empty parameter in function

Post by SparkOut » Sat Apr 04, 2015 12:16 pm

Longer answer, download, unzip and investigate this demo
Attachments
value_demo.livecode.zip
(865 Bytes) Downloaded 232 times

guenter.g
Posts: 1
Joined: Mon Jul 28, 2014 8:44 pm

Re: Empty parameter in function

Post by guenter.g » Tue Apr 14, 2015 4:57 pm

You can use the functions paramcount() and param() (see in dictionary)

Code: Select all

function play1 item1, item2, item3, item4, item5, item6
   repeat with tParam = 1 to paramcount()
      if param(tParam) is empty then
         answer ("item" & tParam && "is empty!")
      end if
   end repeat
end play1

Post Reply