Simplifying Code

Can someone simplify this mess:

3 Likes

Use and & or logic blocks

3 Likes

You need to use the ā€˜set options idx’ variable block before using it in an if statement. Also variables are only made to hold numbers (so I’ve been told for a very long time).

Give me a few more details and explain what I’m looking at and I bet I can make a much simpler mess.

5 Likes

It’s a voting system where the host tallys up the votes for 2 options. If it finds a tally hogher than the other options, then it sets the highest option to that and saves it to a text property. To make the length of the string always 2, if the length of it is 1, then you join a 0 onto the front of it. If you find one that’s equal to the highest option, then you add it to the property.

1 Like

What’s the setup outside of the block code (how are people voting?)

3 Likes

No, you can store anything in variables.

2 Likes

I’ve experienced a lot of trouble (not to mention all of the others I’ve helped that have suffered from the same problem) with text strings in variables, mainly when checking in if/else statements. I’m pretty sure it has something with the way gimkit itself is made, as normally this wouldn’t be an issue.

4 Likes

There’s a similar problem in Java with strings. Basically, there’s things that are objects, and each object is treated separately. Strings are objects that encode the text, and in Java, the equals sign checks if the 2 things are the same exact thing. So if you have 2 different strings that have the same contents, but are different objects, then the equals operator treats them as different and returns false. It could be the same problem here, but I’m not sure.

2 Likes

You walk into a zone which increases a counter which sets a property named ā€œOption (#)ā€

I went ahead and found a way to simplify it. If anyone can find any more ways to simplify it, let me know.


I don’t think this is going to be possible, but if anyone could get this down to 42 or lower, that would be great! I’m at 60 right now.

Instead of adding 1 to the property at the top, why don’t you just set the variable to the property +1? It would save 4 blocks and I don’t think it would ruin anything (not sure what the ā€œvote finalizeā€ is though).

3 Likes

Vote finalize runs another block. I wanted to see if I could combine the two.

You can convert the top line of code to the bottom, and you save 1 block.

3 Likes

You can save the first if block by making the trigger be player scope, default inactive and activating it with a game start lifecycle. (-3)

Change the last if statement to (-3)

3 Likes

Instead of setting the most votes property and options idx property to 0 using blocks, broadcast on a channel to use a counter to set them to 0 (-4)

You might want to think about shifting the Beginning variable up by 1 to save 2 blocks. You’ll have to shift reference to options string though, so I don’t know if you want to do that.

If you do all of this, you’ll have 6 blocks left. Following slim’s advice, you only need 5 more blocks. If you tell me more about the logic that these blocks run in, I may be able to get it down to fit into a single block.

3 Likes

Thanks a ton for the help. I modified a few things, and here was the final result:


Used some counters, as you suggested, to update the properties.

1 Like

This topic was automatically closed 3 hours after the last reply. New replies are no longer allowed.