Log in
Search
GameML File Sharing
USERNAME: gamemladmin@gmail.com PASSWORD: gamemlsite Upload Here: https://gameml.forumotion.com/GameML-File-Sharing-h3.htmPlease add only games.non-duplicate random number generation
4 posters
:: Game Making :: Game Maker Help :: Game Dev. Q&A :: GML help (Coding)
Page 1 of 1
non-duplicate random number generation
The topic title is a mouthful, but accurate lol. I have a game I'm tinkering with titled Froggo (at least it's called that for now) it involves the play area having random numbers from 1-75 on 24 different tiles. You can play the prototype on yoyo here To get the numbers on the tiles, I put in the tile object creation event:
number=floor(random(74))+1
Using the floor command gets rid of any decimals, but I'm running into a problem with duplicate number (ie number 25 on 6 different tiles). The ideal is to have no duplicate numbers on any of the tiles. I know putting the code in the create event probably isn't the smartest way to go about it, but I'm just not sure how create the desired result. Any pointers?
Regards,
John,
number=floor(random(74))+1
Using the floor command gets rid of any decimals, but I'm running into a problem with duplicate number (ie number 25 on 6 different tiles). The ideal is to have no duplicate numbers on any of the tiles. I know putting the code in the create event probably isn't the smartest way to go about it, but I'm just not sure how create the desired result. Any pointers?
Regards,
John,
Re: non-duplicate random number generation
can you give more actions for it like if there was something in the draw event
Re: non-duplicate random number generation
What I'm missing is a way to determine when there's duplicates, and then take some sort of action to correct it... or something I'm suspecting I need something in the room create code, I just can't quite wrap my mind around what I would need to meet my desired result :p Thanks all the same though!
Re: non-duplicate random number generation
maybe something like this
room code
then on your event put it in the step event
then try that if that does not work you might have to make different varibles and objects for each square
room code
- Code:
global.empty=0
then on your event put it in the step event
- Code:
if global.empty=0
{
number=floor(random(74))+1
global.empty=1
}
then try that if that does not work you might have to make different varibles and objects for each square
Re: non-duplicate random number generation
lol, we were both thinking along the same lines I think something like this might do it I'm going to try it out
Re: non-duplicate random number generation
Hey! were'd my last message go!?! I had a bunch of code writting out similar to what you have, and now it's gone! >:c anyway, I'm going to try it out
Re: non-duplicate random number generation
Ug, it didn't really work out, even if I set up global variables to account for the numbers, I don't know how to make the object "reset" to try again. Even if I could, in theory, it could go on forever until it reaches a untaken number. I'm stumped
Re: non-duplicate random number generation
no i meant like
on the second on
room create
step
on sqaure one
and same for the rest of square accept on square two the varible would be global.squaretwo ect..
on the second on
room create
- Code:
global.squareone=0
global.squaretwo=0
//ect.
step
on sqaure one
- Code:
if global.squareone=0
{
number=floor(random(74))+1
global.empty=1
}
and same for the rest of square accept on square two the varible would be global.squaretwo ect..
Re: non-duplicate random number generation
Sorry, I don't get it How would that prevent duplicate numbers? Thank you for helping! I'm not smart lol
fooey- Moderator
- Posts : 1422
Points : 55590
GameML Reputation : 1
Join date : 2009-07-10
Age : 29
Location : here
Re: non-duplicate random number generation
This topic is still open! i can't figure it out Thanks to all who have replied
Re: non-duplicate random number generation
could you like give me a gmk whith just the blocks with the numbers in it
Re: non-duplicate random number generation
i will probally finnish it on monday if don't get on the computer
Re: non-duplicate random number generation
Posted a GMK on our SkyDrive to help clarify the problem, you can find it here:
http://cid-938ebb7f49a5a4e7.skydrive.live.com/self.aspx/tile^_number/tile^_numbers.gmk
(The Skydrive link is acting weird, just copy & paste this link into your browser)
Thanks to all who reply
http://cid-938ebb7f49a5a4e7.skydrive.live.com/self.aspx/tile^_number/tile^_numbers.gmk
(The Skydrive link is acting weird, just copy & paste this link into your browser)
Thanks to all who reply
Re: non-duplicate random number generation
Well you could just do the really hard thing to do and make like 50 individual tiles. And then if the number of two(or more) tiles is the same all the tiles get new numbers.
Re: non-duplicate random number generation
One thing I'm trying to avoid is having the numbers change after the object is created (although if I can't figure out a way to do that, I guess I'll have to live with it ) That idea isn't bad though, I'll have to keep kicking around that idea I didn't know this would be so hard
Thanks for your help!
John,
Thanks for your help!
John,
Re: non-duplicate random number generation
-js1210- wrote:Well you could just do the really hard thing to do and make like 50 individual tiles. And then if the number of two(or more) tiles is the same all the tiles get new numbers.
Just to let you know I meant only the tiles that have the same numbers.
Re: non-duplicate random number generation
Fixed the problem using a ds_list! Thanks for helping everyone!
Similar topics
» Something random I've got on my mind
» Random stuff you have laughed at
» a 2nd batch of mods for Moderators number double, the 2nd mod.
» Random stuff you have laughed at
» a 2nd batch of mods for Moderators number double, the 2nd mod.
:: Game Making :: Game Maker Help :: Game Dev. Q&A :: GML help (Coding)
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|