C
C#2y ago
Ordenary

❔ Only one bullet will reset

The code i've entered is to reset the bullets back to a random starting position after choosing to play again, but only one bullet comes back
10 Replies
matkoch
matkoch2y ago
is it possible that all bullets are in the same location? they all receive the same values for left and top
Ordenary
OrdenaryOP2y ago
um idk but this is the code for their positions
Ordenary
OrdenaryOP2y ago
Ordenary
OrdenaryOP2y ago
so they should all spawn randomly no?
Angius
Angius2y ago
You create a new instance of Random each time, so it's possible all generated values are the same You should use Random.Shared.Next() instead Or, if you're using an old version of .NET, have a static property somewhere with a single instance of Random that you would reuse
cathei
cathei2y ago
It looks like you only do rand.Next once and setting same value for every picBulletX
Ordenary
OrdenaryOP2y ago
would i do the same code but make a different variable instead of "randomY"?
cathei
cathei2y ago
Well you need to call rand.Next again if you want different value Use array or list then you can loop instead of making countless variables
TheRanger
TheRanger2y ago
also
picBullet1.Location = new Point(ranX, randomY);
picBullet1.Location = new Point(ranX, randomY);
is cleaner to type than
picBullet1.Top = ranX;
picBullet1.Left = randomY;
picBullet1.Top = ranX;
picBullet1.Left = randomY;
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server