revUp - Updates and news for the LiveCode community
Issueu 119 | September 29th 2011 Contact the Editor | How to Contribute

Tips and tricks from RunRev forums
Participate in our great user community for invaluable advice and assistance in getting the most out of your LiveCode

by Heather Nagey

The LiveCode user community is one of its greatest assets. You guys are great, it always astonishes me how generous you all are with your time and coding help. From time to time it's interesting to take a look at the user forums and see what kind of tips you, the users, are exchanging. Here is a selection of recent posts.

Name your own controls

Forum thread:

http://forums.runrev.com/viewtopic.php?f=6&t=8600

The question from BarrySumpter:

If I add a Button its name is Button. If I add another Button its name is Button.

Can you please add a way where I can name my first button automatically as
btnButton1 and when I add another button its name is btnButton2.

And if I copy a button, say copy btnAdd, and paste, I'd like the option to automatically add the button with the name btnAdd2.

The answer from splash21:

Hi, Barry - I needed a break from what I was working on, so here's a start. It's a tiny plugin - just open the stack. There's one button to start and stop the functionality which is to rename newly created controls by adding an index value to the name. The code is in the 'FrontScript' button - which is hidden, so access it through the application browser.

To test: load the stack, press 'Start' , drag some controls on to a new stack, check the names.

Download the stack here.

Pretty neat, I think you'll agree. As one of the other posters in this thread said, if LiveCode doesn't already do it, just roll your own.

http://forums.runrev.com/viewtopic.php?f=7&t=9053

Variable names in variables

Forum thread:

http://forums.runrev.com/viewtopic.php?f=7&t=9033

The question, from WaltBrown:

If I have a local variable that contains a string which is the name of another variable, how do I get at the contents of the inner variable?

put 5 into variable1
put "variable1" into variable2

I want to get "5" from variable2. I tried value(variable2), but that of course gives me "variable1", unless it is a system global preceded with a dollar sign, as in:

put "$APPDATA" into variable2

value(variable2) returns "C:\Users\Walt\AppData\Roaming".

answer 1, from klaus:

although holding variable names in other variables is not really recommended unless avoidably, you can make this via a DO statement!

put 5 into variable1
put "variable1" into variable2
do ("put" && variable2 && "into variable3")
put variable3
## Will put 5 into variable3

answer 2, from jacque:

I don't think you need "do". This works for me:

on testvar
   put 5 into var1
   put var1 into var2
   put var2
end testvar

Leave off the quotes and the value is used instead of the variable name.

This shows that there is often more than one way to do something, depending on the exact outcome you are looking for.

How can I see all scripts in stack?

http://forums.runrev.com/viewtopic.php?f=7&t=8931

The question, from jpottsx1:

I'm sure this is easy and I've overlooked it somehow, but I need to know how can I see all scripts in stack in one place?

I am hoping that I can see the scripts one after the other without having to click thru to view each script.

answer 1, from bn:

http://revonline2.runrev.com/stack/282/Script-Reporter
and there is another one based on above script-reporter by D. Glass. Search for script reporter. You can also access revOnline from within Livecode: user samples

jpottsx1 wanted just a bit more:

Thanks for the link it looks good. But is there a way to also be able see all the scripts, then bulk edit the scripts with search and ?

bn has the answer:

if you want to do a find/replace then you can do that natively. In the Edit Menu > Find and Replace. Choose Stack, make shure "script" is the only option ticked. Do a search. If there was a hit then enlarge the window by dragging in the bottom-right corner, you will see all occurences of the search term. (You can double-click on the listed object where the object was found to go directly to the script) At the bottom you have the option to replace, enter the new term and it will replace all occurences of your search term in whatever you had chosen, card, stack, all open stacks etc.

BUT please be careful, work on a copy of your stack. The replace function also replaces partial matches. That got me a while ago. Use spaces to mark a word if the search term is a word, etc. Make shure your search term is unambiguous.

A search for mouse and a replace RAT would give you "on RATup". Livecode does not like: on RATup / end RATup

If you want to write/edit whole scripts outside of the script editor you could probably hack the script reporter to set the scripts of the objects to the changed scripts.

You may find the rest of this thread amusing, ending up with code for recursive hamsters...of course this does illustrate the downside to participating in the forums. You can end up spending a lot of time just being entertained.

So come on in! If you aren't already a forum member, don't be shy, sign up here:

http://forums.runrev.com

You are certain to learn all sorts of things about LiveCode that you didn't even know you needed to know!

About the Author

Heather Nagey is Customer Services Manager for RunRev Ltd.

 

Main Menu

What's New

Sign up for the September Academy