condense this code

  • 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.

cheatchki

Supporter ++
Jun 26, 2017
49
1
8
24
I am looking to condense this code, however I can't find any solutions that work.

code_language.skript:
on rightclick on cobblestone:
    if block 2 north of event-block is air:
        add north to {_directions::*}
    if block 2 east of event-block is air:
        add east to {_directions::*}
    if block 2 south of event-block is air:
        add south to {_directions::*}
    if block 2 west of event-block is air:
        add west to {_directions::*}
        
    if size of {_directions::*} != 0:
        set {_direction} to random integer from 1 to (size of {_directions::*})
        if {_directions::%{_direction}%} is north:
            set block 1 north of event-block to cobblestone
            set block 2 north of event-block to cobblestone
            
        if {_directions::%{_direction}%} is east:
            set block 1 east of event-block to cobblestone
            set block 2 east of event-block to cobblestone
            
        if {_directions::%{_direction}%} is south:
            set block 1 south of event-block to cobblestone
            set block 2 south of event-block to cobblestone
            
        if {_directions::%{_direction}%} is west:
            set block 1 west of event-block to cobblestone
            set block 2 west of event-block to cobblestone

The main issue I am having is that I would like to set the direction via variable however that doesn't work, so any one else have any other ideas.
 
While you can't use variables for directions, this may work
code_language.skript:
loop 2 times:
  set block loop-num (random direction out of ({_direction} where [true])) of event-block to cobblestone
 
Last edited:
hmm Ill try it tonight. and get back to you
[doublepost=1507071582,1507055484][/doublepost]Sadly, no that doesn't work. I will most likely go and request an enchantment to add variable support in the block expression
 
Status
Not open for further replies.