Page 1 of 1

Multiplying 2 temporary variables & Using custom handlers

Posted: Wed May 29, 2013 10:52 am
by ninjabunny14
Hi guys,

When I press a button on my card it uses the following code:

Code: Select all

on mouseUp
   send Calculate to card "Steve"
end mouseUp
This brings up an error saying it can't find handler. Isn't calculate meant to turn into a custom handler?

Anyway,

When that part was working (it just stopped working after I closed and re-opened it) I was having issues with the Calculate command anyway
My code is as follows:

Code: Select all

on Calculate
   --   Stores the price and percentage into temporary variables
   set the tPrice of this card to field "Price Input"
   set the tUO of this card to (4/100)
   set the tAccUO of this card to (multiply (tUO of this card,tPrice of this card))
end Calculate
I haven't used the mutliply command but the dictionary reffered me to multiply as opposed to *.
It comes up with error: compilation error at line 11 {that is the line with set the tAccUO...} (Function: separator is not a ',') near "of", char 46

Where have I gone wrong please guys?

Thx :D

Re: Multiplying 2 temporary variables & Using custom handler

Posted: Wed May 29, 2013 11:08 am
by icouto
In LiveCode, whenever the compiler comes across a word it doesn't know, it will assume it is a variable.

The 'send' command requires a string. Normally, you'd use it like this:

Code: Select all

send "myCommand"
If I write instead:

Code: Select all

send myCommand
...LiveCode will likely think that 'myCommand' is a variable, and will try to evaluate it to get the string it needs.

It seems what you need to do is this:

Code: Select all

send "Calculate" to card "Steve"
Similarly, the problem in your "Calculate" handler seems to be the line:

Code: Select all

set the tAccUO of this card to (multiply (tUO of this card,tPrice of this card))
When you are accessing custom properties, you should use "the <property name>". If you omit the "the", the compiler thinks that the word 'tUO' is probably a variable, rather than a property, and it chokes! :-)
The following compiles without any problems:

Code: Select all

set the tAccUO of this card to (multiply(the tUO of this card,the tPrice of this card))
I hope this helps!

Re: Multiplying 2 temporary variables & Using custom handler

Posted: Wed May 29, 2013 11:12 am
by Simon
hmmm... you've got a bit too much going on.

on mouseUp
Calculate
end mouseUp

on Calculate
put (fld "Price Input" * (4/100)) into tAccUO
end Calculate

Simon

Edit: Oh yes... maybe it's a custom property.

Re: Multiplying 2 temporary variables & Using custom handler

Posted: Wed May 29, 2013 11:14 am
by ninjabunny14
@icouto
Thanks ever so much it almost works!
However, with the new code you sent me:

Code: Select all

set the tAccUO of this card to (multiply(the tUO of this card,the tPrice of this card))
Still comes up with and error :O
execution error at line 11 (Function: error in function handler) near "multiply", char 33

I promise you I copied and pasted it. Any ideas?

Re: Multiplying 2 temporary variables & Using custom handler

Posted: Wed May 29, 2013 11:16 am
by ninjabunny14
@ Simon
Simon wrote: on Calculate
put (fld "Price Input" * (4/100)) into tAccUO
end Calculate
What does fld mean?

Thanks for all the help! :)

Re: Multiplying 2 temporary variables & Using custom handler

Posted: Wed May 29, 2013 11:20 am
by Simon
Shorthand for field :)

Simon

Re: Multiplying 2 temporary variables & Using custom handler

Posted: Wed May 29, 2013 11:25 am
by ninjabunny14
Thanks so much all! It works!

I was kinda writing too much but thanks to all of you!

:D :D :D :D :D :D :D :D :D :D :D :D

Re: Multiplying 2 temporary variables & Using custom handler

Posted: Wed May 29, 2013 12:16 pm
by Klaus
Hi friends,

MULTIPLY (a reserved word!) is the name of a HANDLER (not a function!) so you would need to:
...
multiply x BY y
...

Best

Klaus