Is there a way for this code to be more simple/ shorter?

Im making a baseball game here, and i have this code set for the bases. but when i press play, it says that the script takes too long to load. so i was wondering if there is a way to make this code here more compact so that the script wont take too long to load (aka show the notification that it took too long to load). heres my game by the way: CoSpaces Edu :: baseball game

1 Like

Hi @Axolotl_Gangster, well done for asking! You definitely can make this simpler, by following these steps:

  1. Move the events out of the repeat block - Events are always running, so don’t need to be in any type of loop.

  2. Put your if statement into a function, and call that function inside every event, at the end

You could optimise further by putting your bases into a list, applying events to bases by looping through that list, like so:

but that gets complicated when you need to give different text to info panels, so perhaps leave that out.

Hope that helps! Let me know if you have any further questions about this. If this solves your problem, please mark this post as the Solution.

Many thanks,
Geoff @ TechLeap

1 Like

where do you get the “check bases” block?

I made it, by clicking Create function in the Functions category. If you can’t see this category, you may need to enable Advanced in Settings. A function is just a labelled box for putting your code in so you can use it in multiple places, a bit like a variable.

1 Like

thank you very much, now the bases work without cospace telling me that the script is too slow. your help saves me from turning in my project unfinished XD

1 Like

You’re welcome. Putting Events inside a loop/repeat block is a common mistake, as many students don’t understand that the Events are ALWAYS listening & waiting for the event to happen.