Dealing with all cases of sheep color efficiently

  • 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.
Apr 4, 2017
16
0
0
42
I'm writing a small script that makes shearing sheep drop 3-5 wool (the vanilla behavior is dropping 1-3 wool). Naturally, the color of the dropped wool should match the color of the sheep:
Code:
on rightclick on a sheep:
    if player's tool is shears:
        set {_color} to color of clicked sheep
        shear the clicked sheep
        set {_woolToDrop} to random integer between 3 and 5
        if {_color} is black:
            drop {_woolToDrop} of black wool block
        else if {_color} is light cyan:
            drop {_woolToDrop} of light blue wool block
        else if {_color} is yellow:
            drop {_woolToDrop} of yellow wool block
        [13 other cases]
Ideally this would handle all colors uniformly, rather than splitting into 16 cases, but I wasn't able to find a way to do this, and so what should take 7 lines instead takes more than 30. There are two issues here:
  1. It would be useful to have a syntax that drops a wool block of a color specified by a variable name. Naively one might try
    Code:
    drop {_woolToDrop} of {_color} wool block
    but this returns a "can't understand this condition/effect" error.
  2. Even with a syntax of the type in (1) there are several colors for which the value returned by color of clicked sheep is not the name used when specifying the color of the wool block (e.g., light cyan vs. light blue in the example above). These cases could each be handled separately, e.g., with code
    Code:
    if {_color} is light cyan:
        set {_color} to light blue
    for each such color, but this is not very elegant. (For portability reasons, I don't want to modify the alias file.)
    Is there a better way to achieve this?
 
Status
Not open for further replies.