Multiplying 2 temporary variables & Using custom handlers

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
ninjabunny14
Posts: 27
Joined: Wed May 29, 2013 10:32 am

Multiplying 2 temporary variables & Using custom handlers

Post by ninjabunny14 » Wed May 29, 2013 10:52 am

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
Getting there... Very slowly ;)

icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am

Re: Multiplying 2 temporary variables & Using custom handler

Post by icouto » Wed May 29, 2013 11:08 am

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!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Multiplying 2 temporary variables & Using custom handler

Post by Simon » Wed May 29, 2013 11:12 am

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.
Last edited by Simon on Wed May 29, 2013 11:15 am, edited 1 time in total.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

ninjabunny14
Posts: 27
Joined: Wed May 29, 2013 10:32 am

Re: Multiplying 2 temporary variables & Using custom handler

Post by ninjabunny14 » Wed May 29, 2013 11:14 am

@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?
Getting there... Very slowly ;)

ninjabunny14
Posts: 27
Joined: Wed May 29, 2013 10:32 am

Re: Multiplying 2 temporary variables & Using custom handler

Post by ninjabunny14 » Wed May 29, 2013 11:16 am

@ Simon
Simon wrote: on Calculate
put (fld "Price Input" * (4/100)) into tAccUO
end Calculate
What does fld mean?

Thanks for all the help! :)
Getting there... Very slowly ;)

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Multiplying 2 temporary variables & Using custom handler

Post by Simon » Wed May 29, 2013 11:20 am

Shorthand for field :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

ninjabunny14
Posts: 27
Joined: Wed May 29, 2013 10:32 am

Re: Multiplying 2 temporary variables & Using custom handler

Post by ninjabunny14 » Wed May 29, 2013 11:25 am

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
Getting there... Very slowly ;)

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

Re: Multiplying 2 temporary variables & Using custom handler

Post by Klaus » Wed May 29, 2013 12:16 pm

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

Post Reply