Simple Function use

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
mkholcomb@aol.com
Posts: 1
Joined: Sat Jun 11, 2016 6:20 pm

Simple Function use

Post by mkholcomb@aol.com » Sat Jun 11, 2016 6:41 pm

Trying to learnLive code and cannot do even the most simple of programming features ...

I have a single stack and want return a varA from a function disp_to_acceleration and put it into a text field i call AccelValue
my goal is to create a collection of functions . click a button and have it populate different text boxes.

Stuck on the first one.

on mouseUp
put field "FreqValue" into varF -- this works
put field "DispValue" into varD -- this works
let varA= (disp_to_acceleration(varF,varD), stack "Dynamic Conversion") -- this fails
put varA into field "AccelValue"
end mouseUp

with error
button "Button": execution error at line 6 (Chunk: can't find stack), char 1

There are two tabs and one of them says stack "Dynamic Conversion", which is were my function lives.

function disp_to_acceleration(varF,varD)
return varF*varD
end disp_to_acceleration

any help is appreciated. This is the simplist of things to do , but, totally escapes me in LiveCode.

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

Re: Simple Function use

Post by Klaus » Sat Jun 11, 2016 6:54 pm

Hi mkholcomb@aol.com,

1. welcome to the forum! :D

2. to get used to Livecode, I recommend to check these stacks:
http://www.hyperactivesw.com/revscriptc ... ences.html

For your problem, declare the function like this:

Code: Select all

function disp_to_acceleration var1,var2
  return var1*var2
end disp_to_acceleration
And use it like this:

Code: Select all

on mouseUp
  put field "FreqValue" into varF -- this works
  put field "DispValue" into varD -- this works
  ## let varA= (disp_to_acceleration(varF,varD), stack "Dynamic Conversion") 
  ##  this fails, because it is Basic or something like this :-)

  ## Correct use of function in LC
  ## put disp_to_acceleration(varF,varD) into varA
  ## put varA into field "AccelValue"

  ## Or shorter:
  put disp_to_acceleration(varF,varD) into field "AccelValue"
end mouseUp
Best

Klaus

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

Re: Simple Function use

Post by dunbarx » Sun Jun 12, 2016 1:25 pm

You have programmed before.

When you wrote

Code: Select all

"let varA= (disp_to_acceleration(varF,varD), stack "Dynamic Conversion") -- this fails"
Where did you get the idea that "let" was a native word? I am not chastising, just trying to make a point. A new language requires learning a new vocabulary and syntax. Take Klaus advice and dig into the basics. You are at an advantage in that you already have coded. You are at a disadvantage in that you need to unlearn quite a bit.

Craig Newman

Post Reply