You'll need to create a variable (counter) and (checking) for this.
set [counter v] to [1] set [checking v] to [0] if <[list v] contains [silver]> repeat until <<(counter) < ((length of [list v])-(1))>or<(checking)=(1)>> if <<item (counter) of [list v]>=[silver]> delete (counter) of [list v] set [checking v] to [1] else change [counter v] by (1) end end end
Offline
if <[list v] contains [silver]> set [counter v] to [1] repeat until <(counter) > (length of [list v])> if <<item (counter) of [list v]>=[silver]> delete (counter) of [list v] set [checking v] to (length of [list v]) end change [counter v] by (1) end end
Offline
TorbyFork234 wrote:
You'll need to create a variable (counter) and (checking) for this.
set [counter v] to [1] set [checking v] to [0] if <[list v] contains [silver]> repeat until <<(counter) < ((length of [list v])-(1))>or<(checking)=(1)>> if <<item (counter) of [list v]>=[silver]> delete (counter) of [list v] set [checking v] to [1] else change [counter v] by (1) end end end
Pretty sure you need a "greater than" in that script, not a "less than"
Offline
Guys, you're over-complicating this.
set [counter v] to [1] if <[list v] contains [silver]> repeat until <(item (counter) of [list v]) = [silver]> change [counter v] by (1) end delete (counter) of [list v] endThat will only delete the first "silver" in the list. If you would like to delete all the "silver"s in the list, do this:
if <[list v] contains [silver]> repeat until <not <[list v] contains [silver]>> set [counter v] to [1] repeat until <(item (counter) of [list v]) = [silver]> change [counter v] by (1) end delete (counter) of [list v] end end
Last edited by BirdByte (2012-09-12 09:23:07)
Offline
BirdByte wrote:
Guys, you're over-complicating this.
set [counter v] to [1] if <[list v] contains [silver]> repeat until <(item (counter) of [list v]) = [silver]> change [counter v] by (1) end delete (counter) of [list v] endThat will only delete the first "silver" in the list. If you would like to delete all the "silver"s in the list, do this:if <[list v] contains [silver]> repeat until <not <[list v] contains [silver]>> set [counter v] to [1] repeat until <(item (counter) of [list v]) = [silver]> change [counter v] by (1) end delete (counter) of [list v] end end
That one is the simplest ^ and also easiest to understand. The counter variable goes through each item of the script, first, second etc until the item which corresponds to the counter value, eg the 34th value = silver. It then deletes this item.
The only problem with this is that you delete a value from the list. If the first and second items are silver, you would encounter a problem. Counter, =1, detects silver and deletes it, and then sets counter to 2. BUT, the original second item (silver) is NOW item 1, and the counter won't check it but instead move on. Theoretically, you could still have silver's in the list. To correct this simply don't change the counter if silver was detected:
if <[list v] contains [silver]> set [counter v] to (1) repeat until <(counter) > (length of [list v])> if <(item (counter) of [list v]) = [silver]> delete (counter) of [list v] else change [counter v] by (1)
Last edited by Prestige (2012-09-12 12:30:03)
Offline
BirdByte wrote:
Guys, you're over-complicating this.
...code and stuffif <[list v] contains [silver]> repeat until <not <[list v] contains [silver]>> set [counter v] to [1] repeat until <(item (counter) of [list v]) = [silver]> change [counter v] by (1) end delete (counter) of [list v] end end
As long as we're simplifying, you don't even need that first if statement. And using "repeat until" rather than an if statement means you are unnecessarily looping through parts of the list that you've already checked.
Edit: don't use the script below
set [counter v] to (1) repeat until <not <[list v] contains [silver]>> if<(item (counter) of [list v]) = [silver]> delete (counter) of [list v] end change [counter v] by (1) end
Last edited by MoreGamesNow (2012-09-12 16:33:49)
Offline
MoreGamesNow wrote:
BirdByte wrote:
Guys, you're over-complicating this.
...code and stuffif <[list v] contains [silver]> repeat until <not <[list v] contains [silver]>> set [counter v] to [1] repeat until <(item (counter) of [list v]) = [silver]> change [counter v] by (1) end delete (counter) of [list v] end endAs long as we're simplifying, you don't even need that first if statement.
And using "repeat until" rather than an if statement means you are unnecessarily looping through parts of the list that you've already checked.
set [counter v] to (1) repeat until <not <[list v] contains [silver]>> if<(item (counter) of [list v]) = [silver]> delete (counter) of [list v] end change [counter v] by (1) end
That script won't work because counter will go higher than the length of the list. Use this, then:
repeat until <not <[list v] contains [silver]>> set [counter v] to (1) repeat (length of [list v]) if<(item (counter) of [list v]) = [silver]> delete (counter) of [list v] end change [counter v] by (1) end end
Last edited by BirdByte (2012-09-12 14:18:35)
Offline
BirdByte wrote:
That script won't work because counter will go higher than the length of the list. Use this, then:
repeat until <not <[list v] contains [silver]>> set [counter v] to (1) repeat (length of [list v]) if<(item (counter) of [list v]) = [silver]> delete (counter) of [list v] end change [counter v] by (1) end end
Wow, that was embarrassing. Why are you using "repeat until" instead of just the if-block?
Fixed Script from above:
set [counter v] to (1) repeat until <<not <[list v] contains [silver]>> or <(counter) > (length of [list v])>> if<(item (counter) of [list v]) = [silver]> delete (counter) of [list v] end change [counter v] by (1) end
Offline
Here is another way to do it:
set [counter v] to (length of [list v]) repeat until <(counter) = (0)> if <(item (counter) of [list v]) = [silver]> delete (counter) of [list v] end change [counter v] by (-1) end
Last edited by BoltBait (2012-09-12 18:08:20)
Offline