How to use star in the name of a container

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
fmuller
Posts: 11
Joined: Mon Mar 08, 2010 1:02 pm

How to use star in the name of a container

Post by fmuller » Thu Apr 01, 2010 5:42 pm

Hello,

I search a solution for have all button on a card updated in a loop, example below :
In fact I have many button all names started with "btn_U" after I use a number and after I use something.
The goal with the loop is to update every button in a shoot using the * (star)

repeat with tVarCount = 1 to 4
set label of button "btn_U" & tVarCount & "*" to 0
end repeat

My script doesn't work, if you have an idea it could be great.
Thanks Fabrice

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: How to use star in the name of a container

Post by sturgis » Thu Apr 01, 2010 6:19 pm

Change it thusly:

Code: Select all

   repeat with i = 1 to 4
      set the label of button ("btn_U" & i & "*") to 0
   end repeat
This forces evaluation of the "btn_U & i & "*"" FIRST so that the engine just sees button "btn_U1*". If the parens aren't there, the engine expects "to" after "btn_U".

edit: Change the i back to your variable name of course.

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

Re: How to use star in the name of a container

Post by Klaus » Thu Apr 01, 2010 6:29 pm

Grüezi Fabrice,

let me first see if I understand what you are after :)

You have for example 4 buttons on your card named:
btn_U1_something_else
btn_U2_a_different_thing
btn_U3_swiss_cheese
btn_U4_chaes_fondue
?

And you want to set their label to the number 0 in a repeat loop without writing their names?
Or dou you mean to set their label to empty?

Whatever, this will not work with "wildcards" like "*"
A "repeat loop" demands correct names!

BUT you could do something like this:

Code: Select all

...
lock screen

## Now cycle through all buttons on the current card and check their names
repeat with i = 1 to the num of btns of this cd
   if the short name of btn i begins with "btn_U" then
      set the label of btn i to empty ## or "0"
   end if
end repeat
unlock screen
...
Not tested, but should work (Famous last words :lol: )
Hope this helps.


Best from germany

Klaus

fmuller
Posts: 11
Joined: Mon Mar 08, 2010 1:02 pm

Re: How to use star in the name of a container

Post by fmuller » Thu Apr 01, 2010 6:47 pm

sturgis wrote:Change it thusly:

Code: Select all

   repeat with i = 1 to 4
      set the label of button ("btn_U" & i & "*") to 0
   end repeat
This forces evaluation of the "btn_U & i & "*"" FIRST so that the engine just sees button "btn_U1*". If the parens aren't there, the engine expects "to" after "btn_U".

edit: Change the i back to your variable name of course.
Hello,

Thanks for reply. I tried but it doesn't work, error message during execution :
execution error at line 6 (Chunk: no such object) near "btn_U1*", char 17

Fabrice

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: How to use star in the name of a container

Post by sturgis » Thu Apr 01, 2010 7:06 pm

My apologies, misunderstood what you were asking. Go with Klaus and you should be set.

fmuller
Posts: 11
Joined: Mon Mar 08, 2010 1:02 pm

Re: How to use star in the name of a container

Post by fmuller » Thu Apr 01, 2010 8:00 pm

Klaus wrote:Grüezi Fabrice,

let me first see if I understand what you are after :)

You have for example 4 buttons on your card named:
btn_U1_something_else
btn_U2_a_different_thing
btn_U3_swiss_cheese
btn_U4_chaes_fondue
?

And you want to set their label to the number 0 in a repeat loop without writing their names?
Or dou you mean to set their label to empty?

Whatever, this will not work with "wildcards" like "*"
A "repeat loop" demands correct names!

BUT you could do something like this:

Code: Select all

...
lock screen

## Now cycle through all buttons on the current card and check their names
repeat with i = 1 to the num of btns of this cd
   if the short name of btn i begins with "btn_U" then
      set the label of btn i to empty ## or "0"
   end if
end repeat
unlock screen
...
Not tested, but should work (Famous last words :lol: )
Hope this helps.


Best from germany

Klaus
Hi Klaus,

Thanks, you understand well. it works perfectly with cheese and chocolate :D

Cheers from Switzerland.
Fabrice

fmuller
Posts: 11
Joined: Mon Mar 08, 2010 1:02 pm

Re: How to use star in the name of a container

Post by fmuller » Thu Apr 01, 2010 8:02 pm

sturgis wrote:My apologies, misunderstood what you were asking. Go with Klaus and you should be set.
No Problem, I was not so clear, but usage of () is interesting also for some other application :D

Thanks for taking time.

Cheers, Fabrice

Post Reply