Variable Math

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
JwB
Posts: 1
Joined: Sat Jan 28, 2017 1:56 am

Variable Math

Post by JwB » Sat Jan 28, 2017 2:05 am

I am running into problems adding (or another math operation) with variables. I am trying the following with global variables. These are defined in the card script and the action is also in the card script:

put _v1 + _v2 into _vTotal

What I have read so far only concerns adding integers to a variable or adding the variable values to a field and then extracting back out of the field into another variable.

Any advice?

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 365
Joined: Mon Jun 10, 2013 1:32 pm

Re: Variable Math

Post by Lagi Pittas » Sat Jan 28, 2017 3:32 am

sounds like you haven't put the code in a command or function or "executed" it via a button press.

To make it easier when you are playing

put a button on the card and put the following in the script of the button

Code: Select all

global _v1, _v2, _vtotal

on mouseUp
   put 1 into _v1
   put 23 into _v2
   put _v1 + _v2 into _vtotal
   put _vtotal
end mouseUp

And why are you starting the variables with an underscore - extra typing for no reason.

And check out this lesson

http://lessons.livecode.com/m/4603/l/28 ... n-livecode

Regards Lagi

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9662
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Variable Math

Post by dunbarx » Sat Jan 28, 2017 4:51 am

Well I assume your line of code resides in a valid handler, no?

Do each of the variables contain a number? In other words, are you getting a error at runtime, or is the handler not compiling? Otherwise there is nothing wrong with the snippet.

As for underscores, I never use them, simply as a matter of style. I find they remind me of languages I never want to meet. But there is no reason not to, if your style "sees" these sorts of things more easily, or separates them into classes of variables that you find pleasing.

Craig Newman

FlorianCrg
Posts: 1
Joined: Wed Apr 11, 2018 9:41 am

How to script equations

Post by FlorianCrg » Wed Apr 11, 2018 10:00 am

Hi all,

Sorry for my English, I'll try to descibe what is my problem with Scripting on livecode.

I've 4 points A,B,C and E on a image.
with these 4 points I've 2 straights : (AB) and (CE). I know with my script the positions of A,B,C and E.

What I would like to do : having the equation of (AB) and (CE) (like y=ax+b, I know with my script a, and b)

The aim is to find the angle of the intersection of (AB) and (CE).

If it is necessary, I can post the script :)

kind regards
Florian

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Variable Math

Post by sphere » Wed Apr 11, 2018 11:43 am

message 1 and 4 are troll/ nonsense messages

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Variable Math

Post by Klaus » Wed Apr 11, 2018 11:47 am

sphere wrote:
Wed Apr 11, 2018 11:43 am
message 1 and 4 are troll/ nonsense messages
What makes you think so?
The look like legitimate questions to me.

But don't worry, I have an eye on EVERTHING here in the forum! :D

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Variable Math

Post by sphere » Wed Apr 11, 2018 11:51 am

Hoi Klaus,

i putted this in the "exclamation mark": "These are spam/troll messages, why 2 person login with their first message ever on the same subject ?"

Thanks for keeping this forum healthy :)

Gruessen!

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Variable Math

Post by Klaus » Wed Apr 11, 2018 12:00 pm

Dag Sphere,

yes, I read your report, but the user names and posting are in fact different!
What am I missing?

Groetjes (Grüße)

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9662
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Variable Math

Post by dunbarx » Wed Apr 11, 2018 2:15 pm

If you take the slope of each line, and it seems you know how to do that, then each slope can form a triangle upon which you can derive the tangent. The difference between the two arcTangents will be the difference in the two angles.

It matters how you visualize these lines, of course; you need to think of them both "radiating out" from the origin, or at least oriented similarly based on the origin.

Once you have a single angle, you can derive the other three. The opposite will be the same, and the adjacent will be 180 - that angle.

Craig Newman

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Variable Math

Post by sphere » Wed Apr 11, 2018 6:22 pm

Hi Klaus, it was a feeling i had, i found it a bit strange, despite the different names.

I saw such things before, 1 message with questions and never a reply from the author again, except the people willing to help.

But maybe i'm wrong, we'll have to see :mrgreen:

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9834
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Variable Math

Post by FourthWorld » Wed Apr 11, 2018 11:41 pm

I read the report as well (thanks for submitting it, Sphere), and my take was similar to Klaus'. The only thing worse than having a spam-filled forum would be a forum where merely improper English was treated like spam.

The posts themselves contained no ads or links, and neither do the profiles. If they were intended as spam they should give up their spam jobs and become English teachers since their English is more effective than their spamming abilities. :)

For the moment all available evidence is plausibly explained by the content. My default on these things is like Klaus': to maintain a welcoming flavor to this forum, I tend to delete only posts that are clearly either spam or completely irrelevant.

If there's a chance it may be a real person wanting to learn LiveCode, we want to help them.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Variable Math

Post by sphere » Thu Apr 12, 2018 12:12 pm

The only thing worse than having a spam-filled forum would be a forum where merely improper English was treated like spam.
I have no problems with that at all, i make many mistakes in foreign languages. I can read thru that.
If there's a chance it may be a real person wanting to learn LiveCode, we want to help them.
Of course, i'd like to help too

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”