Custom command with multiple parameters

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
guillem
Posts: 13
Joined: Tue Apr 12, 2016 7:36 pm

Custom command with multiple parameters

Post by guillem » Tue Apr 12, 2016 7:52 pm

This is my first post btw so: hello all!

I'm trying to make a custom command take two parameters in this fashion:

Code: Select all

command twoParams pOne, pTwo
   -- do things with pOne and pTwo
end command
I'm calling it as twoParams("foo", "bar"), and I was expecting to see that pOne = "foo" and pTwo = "bar" (same as with custom functions), but what I get is pOne = "foo,bar" and pTwo = "". I don't know if I'm not seeing some stupid big obvious typo.

I'm using LC8DP16 on OSX Yosemite (RC1 still downloading, didn't try yet).

Edit: thanks!
LC8, OSX 10.9.5 (Mavericks)

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

Re: Custom command with multiple parameters

Post by Klaus » Tue Apr 12, 2016 8:00 pm

Grüezi guillem,

1. welcome to the forum! :D

2. Hm, you created a COMMAND:
-> command twoParams pOne, pTwo
but call it like a FUNCTION:
-> twoParams("foo", "bar")

Not sure what you are exspecting or what exactly should happen
or how your command returns anything?


Best

Klaus

guillem
Posts: 13
Joined: Tue Apr 12, 2016 7:36 pm

Re: Custom command with multiple parameters

Post by guillem » Tue Apr 12, 2016 8:11 pm

Grüezi wohl, Klaus, and thanks for the welcome!

Well in fact I was not expecting the command to return anything. Elaborating a bit more on my pseudocode:

Code: Select all

command putSomeWordsNicelyAroundTheUI pAlistOfWords pAdifferentListOfWords
   -- chew pAlistOfWords and spit it on the card as a navigation menu
   -- chew pAdifferentListOfWords and spit it on the card as a secondary navigation menu
end command
Those menus are intended to be different every time the command putSomeWordsNicelyAroundTheUI is called, that's why I wasn't using a function; and I was taking for granted that it was allowed for commands too... Maybe it's just a problem of perspective and I should be trying to do the menus differently.
LC8, OSX 10.9.5 (Mavericks)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Custom command with multiple parameters

Post by dunbarx » Tue Apr 12, 2016 8:33 pm

Hi.

Step through these:

Code: Select all

on mouseUp
   put 3 into param1
   put 5 into param2
   answer doubleUp(param1,param2)
   doubleUp param1,param2
end mouseUp

function doubleUp firstArg,secondArg
  return firstArg * 2 & return & secondArg * 2
end doubleUp

on doubleUp firstArg,secondArg
 put  firstArg * 2 & return & secondArg * 2 into fld 1
end doubleUp
The way commands and functions work is similar, but depends on how you want to use them, and where control is delegated to.

Craig Newman

guillem
Posts: 13
Joined: Tue Apr 12, 2016 7:36 pm

Re: Custom command with multiple parameters

Post by guillem » Tue Apr 12, 2016 8:46 pm

Oh!

It was the parentheses!

I feel stupid now :lol:

Thank you Klaus and Craig!
LC8, OSX 10.9.5 (Mavericks)

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

Re: Custom command with multiple parameters

Post by Klaus » Tue Apr 12, 2016 9:19 pm

guillem wrote:It was the parentheses!
That's what I meant with "you are calling it like a function" :D
Glad you got it working now!

guillem
Posts: 13
Joined: Tue Apr 12, 2016 7:36 pm

Re: Custom command with multiple parameters

Post by guillem » Wed Apr 13, 2016 7:31 am

@Klaus,

yes, yes, it makes sense now, but my brain was very busy running into the same wall over and over :oops:
LC8, OSX 10.9.5 (Mavericks)

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

Re: Custom command with multiple parameters

Post by Klaus » Wed Apr 13, 2016 9:36 am

Switch walls from time to time! :D

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

Re: Custom command with multiple parameters

Post by SparkOut » Wed Apr 13, 2016 10:34 am

But don't give up either, the wall will come tumbling down in the end.

http://forums.livecode.com/viewtopic.php?p=40553#p40553

Post Reply