Hello,
I never heard of the wrap operator, how it works?
Please can you explain me the math of it?
Wrap operator
Wrap operator
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- VIP Livecode Opensource Backer
- Posts: 9842
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Wrap operator
Allows you to have a lengthy repeat using a shorter counting range:
http://livecode.wikia.com/wiki/Wrap
http://livecode.wikia.com/wiki/Wrap
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Wrap operator
This relates to LC Script AND LC Builder:
The "wrap" operator is made to adjust the mod operator from counting zero-based (as other languages need it) to count one-based (as LC needs it).
Assume you have a list "A,B,C,D" and you wish to use the items in a never ending row.
Using zero-based counting you count (starting from zero) item number 0,1,2,3,0,1,2,3,0,1,...
And you can achieve this (expressed for comparison in LCS/LCB) by repeating "add 1 to counter".
Then
(1) put counter mod 4 into counter
Using one-based counting you count (starting from one) item number 1,2,3,4,1,2,3,4,1,2,...
And you can achieve this in LCS and LCB by repeating "add 1 to counter".
Then
(2) put ((counter-1) mod 4) + 1 into counter
or
(3) if counter > 4 then put 1 into counter (in LCB use "if ... end if")
or
(4) put counter wrap 4 into counter
The comparison of (1) and (4) shows a simple rule:
For zero-based counting use mod, as in (1),
for one-based counting use wrap, as in (4).
[Similar is valid for counting negative values downwards.]
The "wrap" operator is made to adjust the mod operator from counting zero-based (as other languages need it) to count one-based (as LC needs it).
Assume you have a list "A,B,C,D" and you wish to use the items in a never ending row.
Using zero-based counting you count (starting from zero) item number 0,1,2,3,0,1,2,3,0,1,...
And you can achieve this (expressed for comparison in LCS/LCB) by repeating "add 1 to counter".
Then
(1) put counter mod 4 into counter
Using one-based counting you count (starting from one) item number 1,2,3,4,1,2,3,4,1,2,...
And you can achieve this in LCS and LCB by repeating "add 1 to counter".
Then
(2) put ((counter-1) mod 4) + 1 into counter
or
(3) if counter > 4 then put 1 into counter (in LCB use "if ... end if")
or
(4) put counter wrap 4 into counter
The comparison of (1) and (4) shows a simple rule:
For zero-based counting use mod, as in (1),
for one-based counting use wrap, as in (4).
[Similar is valid for counting negative values downwards.]
shiftLock happens