Page 1 of 1

Function syntax

Posted: Fri Mar 05, 2010 11:59 am
by MCla
I tried to pass two integer number (lets call them xx and yy) to a handler (they are the coordinates of a point on the screen.
Lets call the handler MoveItThere

Code: Select all

on MoveItThere xpos, ypos
set the loc of graphic "littlecircle" xpos/2 &","& ypos/2  -- put the graphic half-from the xpos ypos original position
end MoveItThere
I have then a button with the following handler

Code: Select all

on mouseUp
   put 320 into xx
   put 450 into yy
   MoveItThere (xx,yy)
end mouseUp
I was expecting this to work. But it does not. The MoveItThere handler considers that there is only one passed parameter and that it is a point: i.e. two values separated by a coma are in xpos, the second parameter ypos is empty.
Although the workaround is easy, this behaviour seems strange as the comma is normally the itemdelimiter for parameters and that Revolution supports multiple parameters passed to functions or handlers...

Is this new or am I missing something.

I am using rev 4.0 but I believe this did not happen in 3.5 (I have deleted 3.5 from my machine)

Re: Function syntax

Posted: Fri Mar 05, 2010 1:05 pm
by bn
MCla,
you mix function and command syntax
what you would want here is a command. A function would return something, a command does not.
as a function this works

Code: Select all

on mouseUp
   put 320 into xx
   put 450 into yy
   put MoveItThere (xx , yy) into temp
end mouseUp
function MoveItThere xpos, ypos
   set the loc of graphic "littlecircle" to xpos/2 &","& ypos/2  -- put the graphic half-from the xpos ypos original position
   return empty -- you could even leave this out
end MoveItThere
as a command this works:

Code: Select all

on mouseUp
   put 320 into xx
   put 450 into yy
   MoveItThere xx , yy
end mouseUp
on MoveItThere xpos, ypos
   set the loc of graphic "littlecircle" to xpos/2 &","& ypos/2  -- put the graphic half-from the xpos ypos original position
end MoveItThere
what happend is that enclosing xx,yy in brackets " MoveItThere (xx,yy)" you made Rev evaluate what is inside the brackets and pass both values in the first parameter.
If you use this in a function syntax "put moveItThere (xx,yy) into tWhatever" Rev knows it is a function and passes both parameters without evaluating them first.
regards
Bernd

Re: Function syntax

Posted: Fri Mar 05, 2010 3:45 pm
by MCla
You are of course right.
I used to have a function there and changed it to a command without realizing I needed to change the syntax..


Thanks so much

Cheers,