math.Random(4) runs out

@Andrew_Stacey I think that’s where you, I, and @Ignatz differ in the code we show. You seem to write code that can be used in any type of situation. You try to code so it covers every type of condition because you want your code to be useful to everyone no matter how complex or simple the code is they write. In other words, you want to be thorough. My code is meant to be simple and used in the situation that it’s written for. @Majormorgan said he wanted to expand it to 8 sprites, so that’s what I coded it for. I’m not expecting someone to take this code an use it for 100 or 1000 sprites. But if they did, then as long as the number of sprites on the screen compared to the total number of sprites is low, then this will still work OK. I’m retired, so my days of writing complex code to cover every condition is behind me. I now just code simple, use this in this situation type of code.

@Andrew_Stacey - you also have to bear in mind that @dave1707 has to keep a 300 foot drive clear of snow, which doesn’t leave a lot of time for optimising code :smiley:

I’ll give you one guess what I was doing this morning. 1 week till Spring and we had a blizzard yesterday. 30+ mph wind with snow going sideways creating drifts.

@dave1707 - we had our first rain for 55 days today, 0.2mm. And our first day under 30C for as long as I can remember!

@Majormorgan I updated my above code. I changed the next() function to not use a while loop. I now put the number corresponding to a sprite not on the screen into a table. I then pick a number at random from that table. @Ignatz Right now I would settle for some hot days. We’re you out dancing in the rain. 0.2mm amounts to what, about 3 drops in the rain guage.

@Dave1707 , that’s a nice way to approach it, place the objects not on screen into a table to pick from. That idea is cool. I’ll have a play and change my randomising engine to use that idea. Great!

The reason I can’t use the whole of your code is my engine is created in a different way. As its a constant scrolling game screen and these objects are separate classes, I’m passing data out to the classes through Init and I’m tied to quite a lot of different hit tests and game rules.

I think for my next game I’ll be building a simpler engine but for now I have to modify what I have.

I’ll work on that randomising idea for v1.1 which will have some tweaks, new obstacles and also this new randomiser which will make obstacles appear more frequently and make it more challenging.

We’ve had terrible rain these past 3 weeks in England. Time for the sun to come out :wink:

Thanks
Major

@Majormorgan Glad to hear that you can use something from my code and good luck on your code. If you have any questions, there are a lot of people here to help.