My first Function - but where to put it.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
My first Function - but where to put it.
Written my first function and tested it.
However no matter where I put it I
get a message "Can't find function..."
Tried "card id xxxx of stack "....myprog.rev"
and stack "myprog".
Suggestions please.
However no matter where I put it I
get a message "Can't find function..."
Tried "card id xxxx of stack "....myprog.rev"
and stack "myprog".
Suggestions please.
Life is just a bowl of cherries.
bjb007,
Where did you put the function?
If you want to call the function only from one particular script, I'd put the function into that script (e.g. a button). If you need the function in one substack, you can put the function into the stack script of that substack. If you need it in the entire project, put it into the script of the mainstack. If you need it for many projects, keep it in a library and "start using" the library whenever you need the function.
Best,
Mark
Where did you put the function?
If you want to call the function only from one particular script, I'd put the function into that script (e.g. a button). If you need the function in one substack, you can put the function into the stack script of that substack. If you need it in the entire project, put it into the script of the mainstack. If you need it for many projects, keep it in a library and "start using" the library whenever you need the function.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Library
Mark
Thanks for the tips.
I like the idea of making a library of functions
which was common in pre-windows days.
Your functions were compiled into a *.lib
file and the lib file "included". The individual
functions were called by name.
The function (or was it the whole *.lib file?) was
included in the compiled prog.
So the questions is how much like the
above is the RR way?
Are functions from a library file
compiled with the *.exe? or appear in
the "Externals" directory?
Thanks for the tips.
I like the idea of making a library of functions
which was common in pre-windows days.
Your functions were compiled into a *.lib
file and the lib file "included". The individual
functions were called by name.
The function (or was it the whole *.lib file?) was
included in the compiled prog.
So the questions is how much like the
above is the RR way?
Are functions from a library file
compiled with the *.exe? or appear in
the "Externals" directory?
Life is just a bowl of cherries.
My first Function - but where to put it.
Mark
I have ten buttons and want them all
to execute the function. As an example:
Button01, label 1
In script of "Button01"
code: put label of target into aNumber
OK aNumber = 1
Function name is "SetMoreOrLess"
Still in script of "Button01"
SetMoreOrLess aNumber <--stops on this line
--------------------------------------------------------
Handler: can't find handler
Object: Button01
Line: SetMoreOrLess aNumber
Hint: SetMoreOrLess
---------------------------------------------------------
Debugger doesn't go to the function so either
can't find it (how do I tell?) or some other error.
Don't understand the reference to Button01.
Probably irrelevant?
I have ten buttons and want them all
to execute the function. As an example:
Button01, label 1
In script of "Button01"
code: put label of target into aNumber
OK aNumber = 1
Function name is "SetMoreOrLess"
Still in script of "Button01"
SetMoreOrLess aNumber <--stops on this line
--------------------------------------------------------
Handler: can't find handler
Object: Button01
Line: SetMoreOrLess aNumber
Hint: SetMoreOrLess
---------------------------------------------------------
Debugger doesn't go to the function so either
can't find it (how do I tell?) or some other error.
Don't understand the reference to Button01.
Probably irrelevant?
Life is just a bowl of cherries.
Hi bjb007,
As Klaus says, we will need more info.
All I can so so far is that the offending command is indeed in the script of button "Button01".
Best,
Mark
As Klaus says, we will need more info.
All I can so so far is that the offending command is indeed in the script of button "Button01".
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
I would but...
Would like to post the code but have
run into a problem with Rev when I
started it this morning.
When I tried to open myProg.rev I got
a message that there was already a copy
in memory from the Rev "toolset" directory
named "home.rev".
Don't know how it got there but I deleted
it and restarted Rev. Same result.
Closed Rev, deleted the file, re-booted.
Now I get "Error while initializing
development environment" message.
Before I reinstall Rev does anyone have
an explanation or a quick fix?
PS I could put the code in my "User Space"
if I ever get a response to my request made
some weeks ago ago.
run into a problem with Rev when I
started it this morning.
When I tried to open myProg.rev I got
a message that there was already a copy
in memory from the Rev "toolset" directory
named "home.rev".
Don't know how it got there but I deleted
it and restarted Rev. Same result.
Closed Rev, deleted the file, re-booted.
Now I get "Error while initializing
development environment" message.
Before I reinstall Rev does anyone have
an explanation or a quick fix?
PS I could put the code in my "User Space"
if I ever get a response to my request made
some weeks ago ago.
Life is just a bowl of cherries.
bjb007,
Somehow, you deleted a part of the Revolution software, specifically the Home stack. You need to re-install Revolution. Make sure to delete/uninstall the corrupted copy of Revolution first!
Mark
Somehow, you deleted a part of the Revolution software, specifically the Home stack. You need to re-install Revolution. Make sure to delete/uninstall the corrupted copy of Revolution first!
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Reinstall
Reinstalled and find that, as you say, "home.rev"
is part of the system.
Wonder why I had a message that "myProg.rev"
from the "Toolset" directory and named "home.rev"
was already in memory?
I backed up all my files. Rev won't install
in the same directory over an existing copy.
Would have made things simpler. Many
progs. allow a reinstall in an existing
directory without affecting files other than
its own.
is part of the system.
Wonder why I had a message that "myProg.rev"
from the "Toolset" directory and named "home.rev"
was already in memory?
I backed up all my files. Rev won't install
in the same directory over an existing copy.
Would have made things simpler. Many
progs. allow a reinstall in an existing
directory without affecting files other than
its own.
Life is just a bowl of cherries.
Test Stack
Mark and Klaus - and everyone else too.
I've done a small prog using
the code - RKsubTest.rev
The link is "snipped" and will take
you to Wikifortio.com.
Download it here in a zip file...
http://snipurl.com/209qh
and follow along!
I've done a small prog using
the code - RKsubTest.rev
The link is "snipped" and will take
you to Wikifortio.com.
Download it here in a zip file...
http://snipurl.com/209qh
and follow along!
Life is just a bowl of cherries.
Hi bjb,
hmm, strange code going on
OK, I put this into the stackscript, please see my annotations:
And here is how to call it from your buttons:
Will work with every button on every card in your stack, as long as it has a number in its label
and there are fields named "lblOdd" and "lblEven" on the current card!
Hint:
In the script of your button you use:
Best
Klaus
hmm, strange code going on
OK, I put this into the stackscript, please see my annotations:
Code: Select all
function SetOddAndEven aNumber
if aNumber is among the items of "1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32" then
## You should QUOTE strings like this item list.
## ALWAYS quote NAMES of objects!
## No need for an if else, since you will add 1 to the fields anayway :-)
add 1 to field "lblOdd"
add 1 to field "lblEven"
end SetOddAndEven
And here is how to call it from your buttons:
Code: Select all
on mouseUp
## put label of target into aNumber
## I would rather:
put the label of me into aNumber
## You have to get or put the results of functions into something!
get SetOddAndEven(aNumber)
end mouseUp
and there are fields named "lblOdd" and "lblEven" on the current card!
Hint:
In the script of your button you use:
Code: Select all
...
if aNumber = 1 then
## Here you sure mean FIELD "lblOdd" but write it without quotes,
## so the engine thinks you mean a variable, wich does not exist an so the evaluation will
## always end in false: if lblOdd = 0
if lblOdd = 0 then
put 1 into field lblOdd
...
...
Klaus
Code: Select all
end if
end if
The way it effectively works now, no if-statement is necessary at all.
Just to avoid confusion, an if-statement should finished with "end if":
Code: Select all
if <condition> then
-- do something
end if
if <condition> or <condition> and <condition> then
-- do something
else if <condition> or <condition> then
-- do something else
else -- all other conditions
-- do a default thing
end if
Note that <condition> must always evaluate to true or false.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
First Function
Klaus and Mark
I was looking for something to put
in front of the subroutine name - but
didn't try "get" so expect that was
part of the problem
The amended prog (with more buttons!)
is here...
http://snipurl.com/20aqd
I was looking for something to put
in front of the subroutine name - but
didn't try "get" so expect that was
part of the problem
The amended prog (with more buttons!)
is here...
http://snipurl.com/20aqd
Life is just a bowl of cherries.