Page 1 of 1

My first Function - but where to put it.

Posted: Sat Feb 23, 2008 3:00 am
by bjb007
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.

Posted: Sat Feb 23, 2008 3:09 am
by Mark
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

Library

Posted: Sat Feb 23, 2008 3:53 am
by bjb007
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?

My first Function - but where to put it.

Posted: Sat Feb 23, 2008 4:58 am
by bjb007
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?

Posted: Sat Feb 23, 2008 4:48 pm
by Klaus
Could you please post the complete scripts of the function itself and the "mouseup" (or whatever) handler that shall trigger it?

Guessing takes too much time ;-)

Posted: Sat Feb 23, 2008 5:21 pm
by Mark
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

I would but...

Posted: Sun Feb 24, 2008 12:27 am
by bjb007
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.

Posted: Sun Feb 24, 2008 12:43 am
by Mark
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

Reinstall

Posted: Sun Feb 24, 2008 1:04 am
by bjb007
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.

Test Stack

Posted: Sun Feb 24, 2008 2:14 am
by bjb007
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!

Posted: Sun Feb 24, 2008 12:21 pm
by Klaus
Hi bjb,

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
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:

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
   ...
...
Best

Klaus

Posted: Sun Feb 24, 2008 12:52 pm
by Mark

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

First Function

Posted: Sun Feb 24, 2008 4:45 pm
by bjb007
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