How do I shorten this script? Use 'repeat with'?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I shorten this script? Use 'repeat with'?

ELS Prothero via use-livecode
Hi there,

Another question today.
How do I shorten this script?
----
set the loc of grc "k1" to cardWidth/2,cardHeight/2
set the topleft of grc "k2" to (item 1 of topright of grc "k1" -1, item 2
of topright of grc "k1")
set the topleft of grc "k3" to (item 1 of topright of grc "k2" -1, item 2
of topright of grc "k2")
set the topleft of grc "k4" to (item 1 of topright of grc "k3" -1, item 2
of topright of grc "k3")
set the topleft of grc "k5" to (item 1 of topright of grc "k4" -1, item 2
of topright of grc "k4")
----

I know I should use 'repeat with' but I am stuck.
repeat with x = 2 to 4
put "k" & x into tName
set the topleft of grc tName to (item 1 of topright of. grc....?.... , item
2 of topright of grc ...?....)
end repeat


Any help is appreciated!



greetings,

William
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: How do I shorten this script? Use 'repeat with'?

ELS Prothero via use-livecode
You could use two variables like tName and tPrevious

set the loc of grc "k1" to cardWidth/2,cardHeight/2
put ”k1” into tPrevious
repeat with i = 2 to 5
   put ”k” & i into tName
   set the topleft of grc tName to the topright of grc tPrevious
   put tName into tPrevious
end repeat

Coding out of my head so reserve for mistakes!

:-Håkan
On 12 Nov 2020, 14:50 +0100, William de Smet via use-livecode <[hidden email]>, wrote:

> Hi there,
>
> Another question today.
> How do I shorten this script?
> ----
> set the loc of grc "k1" to cardWidth/2,cardHeight/2
> set the topleft of grc "k2" to (item 1 of topright of grc "k1" -1, item 2
> of topright of grc "k1")
> set the topleft of grc "k3" to (item 1 of topright of grc "k2" -1, item 2
> of topright of grc "k2")
> set the topleft of grc "k4" to (item 1 of topright of grc "k3" -1, item 2
> of topright of grc "k3")
> set the topleft of grc "k5" to (item 1 of topright of grc "k4" -1, item 2
> of topright of grc "k4")
> ----
>
> I know I should use 'repeat with' but I am stuck.
> repeat with x = 2 to 4
> put "k" & x into tName
> set the topleft of grc tName to (item 1 of topright of. grc....?.... , item
> 2 of topright of grc ...?....)
> end repeat
>
>
> Any help is appreciated!
>
>
>
> greetings,
>
> William
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: How do I shorten this script? Use 'repeat with'?

ELS Prothero via use-livecode
Yes, two variables must be the way!

Your suggestion however throws an error (no such object).

greetings,

William





Op do 12 nov. 2020 om 14:57 schreef <[hidden email]>:

> You could use two variables like tName and tPrevious
>
> set the loc of grc "k1" to cardWidth/2,cardHeight/2
> put ”k1” into tPrevious
> repeat with i = 2 to 5
>    put ”k” & i into tName
>    set the topleft of grc tName to the topright of grc tPrevious
>    put tName into tPrevious
> end repeat
>
> Coding out of my head so reserve for mistakes!
>
> :-Håkan
> On 12 Nov 2020, 14:50 +0100, William de Smet via use-livecode <
> [hidden email]>, wrote:
>
> Hi there,
>
> Another question today.
> How do I shorten this script?
> ----
> set the loc of grc "k1" to cardWidth/2,cardHeight/2
> set the topleft of grc "k2" to (item 1 of topright of grc "k1" -1, item 2
> of topright of grc "k1")
> set the topleft of grc "k3" to (item 1 of topright of grc "k2" -1, item 2
> of topright of grc "k2")
> set the topleft of grc "k4" to (item 1 of topright of grc "k3" -1, item 2
> of topright of grc "k3")
> set the topleft of grc "k5" to (item 1 of topright of grc "k4" -1, item 2
> of topright of grc "k4")
> ----
>
> I know I should use 'repeat with' but I am stuck.
> repeat with x = 2 to 4
> put "k" & x into tName
> set the topleft of grc tName to (item 1 of topright of. grc....?.... , item
> 2 of topright of grc ...?....)
> end repeat
>
>
> Any help is appreciated!
>
>
>
> greetings,
>
> William
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: How do I shorten this script? Use 'repeat with'?

ELS Prothero via use-livecode
I added 'the name of grc "k1" to the script and now it works.
Thanks!

set the loc of grc "k1" to cardWidth/2,cardHeight/2
put the name of grc "k1" into tPrevious
repeat with x = 2 to 5
put "k" & x into tName
set the topleft of grc tName to (item 1 of topright of grc tPrevious -1,
item 2 of topright of grc tPrevious)
put tName into tPrevious
end repeat


greetings,

William




Op do 12 nov. 2020 om 15:14 schreef William de Smet <[hidden email]
>:

> Yes, two variables must be the way!
>
> Your suggestion however throws an error (no such object).
>
> greetings,
>
> William
>
>
>
>
>
> Op do 12 nov. 2020 om 14:57 schreef <[hidden email]>:
>
>> You could use two variables like tName and tPrevious
>>
>> set the loc of grc "k1" to cardWidth/2,cardHeight/2
>> put ”k1” into tPrevious
>> repeat with i = 2 to 5
>>    put ”k” & i into tName
>>    set the topleft of grc tName to the topright of grc tPrevious
>>    put tName into tPrevious
>> end repeat
>>
>> Coding out of my head so reserve for mistakes!
>>
>> :-Håkan
>> On 12 Nov 2020, 14:50 +0100, William de Smet via use-livecode <
>> [hidden email]>, wrote:
>>
>> Hi there,
>>
>> Another question today.
>> How do I shorten this script?
>> ----
>> set the loc of grc "k1" to cardWidth/2,cardHeight/2
>> set the topleft of grc "k2" to (item 1 of topright of grc "k1" -1, item 2
>> of topright of grc "k1")
>> set the topleft of grc "k3" to (item 1 of topright of grc "k2" -1, item 2
>> of topright of grc "k2")
>> set the topleft of grc "k4" to (item 1 of topright of grc "k3" -1, item 2
>> of topright of grc "k3")
>> set the topleft of grc "k5" to (item 1 of topright of grc "k4" -1, item 2
>> of topright of grc "k4")
>> ----
>>
>> I know I should use 'repeat with' but I am stuck.
>> repeat with x = 2 to 4
>> put "k" & x into tName
>> set the topleft of grc tName to (item 1 of topright of. grc....?.... ,
>> item
>> 2 of topright of grc ...?....)
>> end repeat
>>
>>
>> Any help is appreciated!
>>
>>
>>
>> greetings,
>>
>> William
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: How do I shorten this script? Use 'repeat with'?

ELS Prothero via use-livecode
Great!

For me it works without adding 'the name of grc ”k1”‘. This works perfectly:

   set the loc of grc "k1" to the width of this card/2, the height of this card/2
   put "k1" into tPrevious
   repeat with i = 2 to 5
      put "k" & i into tName
      set the topleft of grc tName to item 1 of the topright of grc tPrevious - 1, item 2 of the topright of grc tPrevious
      put tName into tPrevious
   end repeat

Did you maybe forget ”grc” somewhere?

:-Håkan
On 12 Nov 2020, 16:00 +0100, [hidden email], wrote:
>
> I added 'the name of grc "k1" to the script and now it works.
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: How do I shorten this script? Use 'repeat with'?

ELS Prothero via use-livecode
In reply to this post by ELS Prothero via use-livecode
Here's another way:

   set the loc of grc "k1" to the loc of this cd
   repeat with x = 2 to 4
     set the topleft of grc ("K" & x) to the topright of grc ("k" & x-1)
     set the left of grc ("k" & x) to the left of grc ("k" & x) - 1
   end repeat

I find it easier to move the graphic one pixel in a second line of script than to mess around
with all those "item 1 of ..."s.


On 11/12/20 7:48 AM, William de Smet via use-livecode wrote:

> Hi there,
>
> Another question today.
> How do I shorten this script?
> ----
> set the loc of grc "k1" to cardWidth/2,cardHeight/2
> set the topleft of grc "k2" to (item 1 of topright of grc "k1" -1, item 2
> of topright of grc "k1")
> set the topleft of grc "k3" to (item 1 of topright of grc "k2" -1, item 2
> of topright of grc "k2")
> set the topleft of grc "k4" to (item 1 of topright of grc "k3" -1, item 2
> of topright of grc "k3")
> set the topleft of grc "k5" to (item 1 of topright of grc "k4" -1, item 2
> of topright of grc "k4")
> ----
>
> I know I should use 'repeat with' but I am stuck.
> repeat with x = 2 to 4
> put "k" & x into tName
> set the topleft of grc tName to (item 1 of topright of. grc....?.... , item
> 2 of topright of grc ...?....)
> end repeat
>
>
> Any help is appreciated!
>
>
>
> greetings,
>
> William
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode