Loop Skript

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

jackass

Member
Nov 8, 2017
16
0
0
23
Hello. I have been attempting to create a Sugar Cane Gen, in which on place of a dirt block, the skript will create layers of sugar cane and dirt on top of each other. The difficulty I am having, is that the purpose of the lines.

if block loop-number above event-block is air:
if block loop-number + 1 above event-block is air:
if block loop-number + 2 above event-block is air:
if block loop-number + 3 above event-block is air:

are to make the skript stop when the gen hits any block other than air. The problem is that this skript is just going through the block and generating more layers above the block.

What it does - https://gyazo.com/d2d848d14bbacca43c17750ecbaa2ddd
What it should do - https://gyazo.com/85af677bfd423407441f7857838b5aaf


Code:
on place:
    if name of held item is "&e&l*&f&l* &e&lCANE &F&LGEN &e&l*&f&l*":
        wait 1 second
        if event-block is dirt:
            loop 20 times:
                if block loop-number above event-block's y-coordinate is more than 254:
                    stop loop           
                else:
                    if event-block is dirt:
                        if block loop-number above event-block is air:
                            if block loop-number + 1 above event-block is air:       
                                if block loop-number + 2 above event-block is air:
                                    if block loop-number + 3 above event-block is air:                   
                                        set block loop-number above event-block to sugar cane
                                        set block loop-number + 1 above event-block to air
                                        set block loop-number + 2 above event-block to air
                                        set block loop-number + 3 above event-block to dirt
                                        wait 1 second
                                    else:
                                        send "1" to player                                       
                                        stop loop                                       
                                else:
                                    send "2" to player                                   
                                    stop loop                                   
                            else:
                                send "3" to player                               
                                stop loop                   
                        else:
                            send "4" to player                       
                            stop loop                   
                    else:
                        send "&8&l[&7&lF&c&lR&8&l] &aCane Gen &7Stopped!" to player                       
                        stop loop
        else:
            send "&8&l[&7&lF&c&lR&8&l] &cCactus Gens &7Only Work In &cYour &7Faction's Land!" to player
 
Last edited:
Hello. I have been attempting to create a Sugar Cane Gen, in which on place of a dirt block, the skript will create layers of sugar cane and dirt on top of each other. The difficulty I am having, is that the purpose of the lines.

if block loop-number above event-block is air:
if block loop-number + 1 above event-block is air:
if block loop-number + 2 above event-block is air:
if block loop-number + 3 above event-block is air:

are to make the skript stop when the gen hits any block other than air. The problem is that this skript is just going through the block and generating more layers above the block.

What it does - https://gyazo.com/d2d848d14bbacca43c17750ecbaa2ddd
What it should do - https://gyazo.com/85af677bfd423407441f7857838b5aaf


on place:
if name of held item is "&e&l*&f&l* &e&lCANE &F&LGEN &e&l*&f&l*":
wait 1 second
if event-block is dirt:
loop 20 times:
if block loop-number above event-block's y-coordinate is more than 254:
stop loop
else:
if event-block is dirt:
if block loop-number above event-block is air:
if block loop-number + 1 above event-block is air:
if block loop-number + 2 above event-block is air:
if block loop-number + 3 above event-block is air:
set block loop-number above event-block to sugar cane
set block loop-number + 1 above event-block to air
set block loop-number + 2 above event-block to air
set block loop-number + 3 above event-block to dirt
wait 1 second
else:
send "&8&l[&7&lF&c&lR&8&l] &aCane Gen &7Stopped!" to player
stop loop
else:
send "&8&l[&7&lF&c&lR&8&l] &cCactus Gens &7Only Work In &cYour &7Faction's Land!" to player
Format your code
 
Could you send us a screenshot of how the "column" is supposed to look like please?
 
Hello. I have been attempting to create a Sugar Cane Gen, in which on place of a dirt block, the skript will create layers of sugar cane and dirt on top of each other. The difficulty I am having, is that the purpose of the lines.

if block loop-number above event-block is air:
if block loop-number + 1 above event-block is air:
if block loop-number + 2 above event-block is air:
if block loop-number + 3 above event-block is air:

are to make the skript stop when the gen hits any block other than air. The problem is that this skript is just going through the block and generating more layers above the block.

What it does - https://gyazo.com/d2d848d14bbacca43c17750ecbaa2ddd
What it should do - https://gyazo.com/85af677bfd423407441f7857838b5aaf


Code:
on place:
    if name of held item is "&e&l*&f&l* &e&lCANE &F&LGEN &e&l*&f&l*":
        wait 1 second
        if event-block is dirt:
            loop 20 times:
                if block loop-number above event-block's y-coordinate is more than 254:
                    stop loop        
                else:
                    if event-block is dirt:
                        if block loop-number above event-block is air:
                            if block loop-number + 1 above event-block is air:    
                                if block loop-number + 2 above event-block is air:
                                    if block loop-number + 3 above event-block is air:                
                                        set block loop-number above event-block to sugar cane
                                        set block loop-number + 1 above event-block to air
                                        set block loop-number + 2 above event-block to air
                                        set block loop-number + 3 above event-block to dirt
                                        wait 1 second
                    else:
                        send "&8&l[&7&lF&c&lR&8&l] &aCane Gen &7Stopped!" to player                    
                        stop loop
        else:
            send "&8&l[&7&lF&c&lR&8&l] &cCactus Gens &7Only Work In &cYour &7Faction's Land!" to player
Your code only stops the loop when the event-block is dirt, not when any of the other checks (`if block loop-num + ...)` return false. You will need to add a `continue` after waiting 1 second, and remove the `else:` (and fix indentation afterwards ofc) from the event-block = dirt check
 
Could you send us a screenshot of how the "column" is supposed to look like please?
What it does - https://gyazo.com/d2d848d14bbacca43c17750ecbaa2ddd
What it should do - https://gyazo.com/85af677bfd423407441f7857838b5aaf

[doublepost=1562914356,1562910233][/doublepost]
Your code only stops the loop when the event-block is dirt, not when any of the other checks (`if block loop-num + ...)` return false. You will need to add a `continue` after waiting 1 second, and remove the `else:` (and fix indentation afterwards ofc) from the event-block = dirt check
I have updated the code within the thread, now it seems to loop once successfully then sends 2 to the player (I number coordinated each step of the loop to see which part caused issues). I am not sure why this part of the loop would cause issues.
[doublepost=1562998974][/doublepost]Fixed the loop, started from scratch on the idea and it seemed to have fixed the problem, whatever it was.
 
Status
Not open for further replies.