|
Title: pools of numbers Post by: BoxedLunch on January 29, 2011, 02:20:26 PM because of my lack of any major programming experience i am having to create a lot of things i've never made before in my extreme tag game. one of these things is a character sprite randomization thingy.
what i am trying to do with this is have the particular set of sprites (character) a player uses be random. so that way when a player joins the game in the menu they are given a random character that nobody is using to cut back time in between games. i know what i want to do but not quite how to do it. here's what i have in mind: 1)playertypes = (pool of numbers from 1-8) 2)"player x" joins game menu 3)"player x" is assigned random character 4)playertypes = (pool of numbers from 1-8) - (numbers of assigned characters) 5)repeat can anyone tell me how to achieve something like this in gamemaker? Title: Re: pools of numbers Post by: ink.inc on January 29, 2011, 02:21:32 PM sprite_index = choose(sprite1,sprite2,sprite3)
etc. etc. Title: Re: pools of numbers Post by: BoxedLunch on January 29, 2011, 03:14:35 PM sprite_index = choose(sprite1,sprite2,sprite3) do i subtract the already chosen sprites within this action? etc. etc. like this? Code: sprite_index = choose((sprite1,sprite2,sprite3)-(chosen sprites)) because that's my problem.Title: Re: pools of numbers Post by: ink.inc on January 29, 2011, 03:18:59 PM o
the choose function doesn't work like that what (I think) you can do is have the choose function choose options from a ds_list and then edit the ds_list as is necessary hit F1 in GM, then search for ds_list It'll explain it a lot better than I can. But it's basically an array of variables/numbers Never really used it, though, but I think that's the direction you COULD head in. Alternately, you could solve the problem hackishly.... Title: Re: pools of numbers Post by: lasttea999 on January 31, 2011, 12:15:03 AM You could also pick numbers at random until the current number doesn't match the number of any existing player. It sounds a bit irresponsible, but it seems like it wouldn't be *too* inefficient?
An example might be: Code: while (check) { check = false; type = random(8); for (i = 0; i < instance_number(obj_player); i++)) { if (type == instance_find(obj_player, i).type) { check = true; } } } Be careful, though--- this code could generate a long if not infinite loop. Title: Re: pools of numbers Post by: BorisTheBrave on January 31, 2011, 11:26:08 AM Get a list of the characters, e.g. 1-8
Randomly shuffle them Then assign the first player the first from the list, the second, the second, etc Title: Re: pools of numbers Post by: ink.inc on January 31, 2011, 11:29:39 AM Ah, and then if a player enters in the middle of the game, just select the next sprite.
That's probably a better idea. Title: Re: pools of numbers Post by: Mitiz on February 02, 2011, 07:00:04 AM Get a list of the characters, e.g. 1-8 this would be the best option, the sprites really only need to be randomised once.Randomly shuffle them Then assign the first player the first from the list, the second, the second, etc Title: Re: pools of numbers Post by: BoxedLunch on February 02, 2011, 08:53:16 PM it worked, or at least from what i can tell, i've had some problems with where i've been placing stuff. i haven't implemented it where it goes, but i got it to randomize the sprites each time, so it should work where i need it.
i've been learning a lot about GML lately. ;D |