How to refer to an object and it's properties in a script?

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
Top Gun
Posts: 2
Joined: Mon Dec 07, 2009 7:42 pm

How to refer to an object and it's properties in a script?

Post by Top Gun » Mon Dec 07, 2009 8:16 pm

Hi everyone!

I searched through the topics on this forum, program documentation and the user guide but didn't manage to find the answer so decided to ask you for some help.

Here is that "monster" :) how in a script can I refer to an object on a stack if I know it's name but also it's name depends on a value of a variable? I.e. I want to have something like this

set visible of graphic "image" + image_number to true
So that if image_number is 34 then the object "image34" will be made visible.

Any ideas?

P.S. I guess there must be some function which can convert an integer digit into a string one. But also I need to merge two strings after that. Can't find any in the documentation, unfortunately.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: How to refer to an object and it's properties in a script?

Post by bn » Mon Dec 07, 2009 8:26 pm

Hi Top Gun,
welcome to the forum.
there is no need in Rev to declare a number as literal. For your case try something like this:

Code: Select all

on mouseUp
   set the visible of field ("f" & 1) to not the visible of field ("f" & 1)
end mouseUp
The same for a variable

Code: Select all

on mouseUp
   put 1 into i
   set the visible of field ("f" & i) to not the visible of field ("f" & i)
end mouseUp
you could use this in a repeat loop. This toggles the visible of field "f1", of course you can just set the visible to false, and it works on images as well. Just don't forget to put it in brackets.
regards
Bernd

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to refer to an object and it's properties in a script?

Post by FourthWorld » Mon Dec 07, 2009 8:28 pm

If your script isn't working try button the part that concatenates the object name between parens to make sure the engine evaluates that first:

set visible of graphic ("image" + image_number) to true
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Top Gun
Posts: 2
Joined: Mon Dec 07, 2009 7:42 pm

Re: How to refer to an object and it's properties in a script?

Post by Top Gun » Mon Dec 07, 2009 8:39 pm

set visible of graphic ("image" & image_num) to true
Works fine!

Thank you, bn :)

Post Reply