• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Kinda complex question involving random selection.

JacobV

Member
So in my game, I have a system which randomly selects a set of attacks. In an object, I create 3 global variables: attack1, attack2, and attack3. I then run a timeline, which runs a script, which selects one of the attack timelines, and then assigns it to the attack1 variable. The first timeline then repeats the process for 2 and 3. Now that I have the set of attacks selected, I run the attack1 timeline. At the end of each attack timeline, it randomly chooses to run attack1, attack2, or attack3, and this forms a loop. This...does work. However, it's a very clunky system, and doesn't allow for much expansion; my goal is to have around 20 possible attacks in each set, and for the attacks to not get repeated; ie, if it runs attack1, it cannot run attack1 for the next attack. Does anyone have any ideas for how I can improve upon this system?
 
F

Fodderbot

Guest
When I read your question, my brain had the exact same thought that Llama_Code proposed. so I am going to second his proposal. Thumbs up to Llama.

you could also keep track of how many times specific attacks have been used and after the randomizing shuffle move the most used to the bottom of the list, or move them down a random amount to make them less likely to come up.
You could also have each enemy or mob contain its own queue that gets filled with the moves planned and it goes on about its marry way until it needs more instructions and then it requests to get replenished with more from an object that is deciding what the group of mobs is doing so there is some teamwork.... humm
 

JacobV

Member
Thanks for the tips! I don't know much about DS Lists, I'll have to study those a bit. Luckily there'll only be one instance at any given time who needs to use it, so there shouldn't be any problems with that.

I still do have a few questions though. There are 6 or 7 timelines that attack1, 2, and 3 choose from, and I plan to add over 100; but I only want to pick a certain number of those. Preferably without making 20 different attack functions...
 

Yal

🐧 *penguin noises*
GMC Elder
You could always stop picking from the shuffled list once you hit that number?
 
D

Dengar

Guest
this is my system that does about the exact same thing. it uses ds_lists and ds_queues but its super simple.
the ds_list is only holding the items/or attacks in your case. and shuffles them into random orders. this main list is never changed.
the ds_queue is where your pulling the attack from. every attack will be on the queue only once and in a random order.
simply change the names of the items to attacks in the ds_queue and it should be plug-n-play

Code:
//this creates your list of attack. mine was items.//put this in create event
item_gen = ds_queue_create();
i_mix = ds_list_create();
ds_list_add(i_mix,"sword");
ds_list_add(i_mix,"hammer");
ds_list_add(i_mix,"water");
ds_list_add(i_mix,"stick");
ds_list_add(i_mix,"stone");
ds_list_add(i_mix,"bucket");
ds_list_add(i_mix,"arrow");


//run this to fill ds_queue with random ordered list.
ds_list_shuffle(i_mix);
erf = 0;
repeat (ds_list_size(i_mix))
{
tj = ds_list_find_value(i_mix,erf);
ds_queue_enqueue(item_gen,tj);
erf+=1
}

//when you need an attack just pull the first attack fr4om the ds_queue
attack1 = ds_queue_dequeue(item_gen);
 
Last edited by a moderator:

JacobV

Member
Thanks, this really helped! However, I do want it to be able to use those attacks again; just not one after the other. For example, let's say I generate an attack set with A, B, C, and D in it, and the generator selects A first; once timeline A is finished, it selects another attack from that same set, but I want it to be unable to select A a second time. So let's say it picks attack C; now it can't use attack C for the next turn, but it CAN select A again. How would I do this?
 
F

Fodderbot

Guest
Shufling list puts them in a different different order to run through s

After running through your shuffled list and doing the actions

You reshuffle list so that you gat a different order for the next set to be done in.

if you have a special instance or change in status you can break out of the while loop reinitialize the list with different actions, or reshuffle early and begin the loop again.
 
D

Dengar

Guest
check if the ds_queue is empty,
if it is empty then run this code again to reload the queue with the same attacks in a new random order
Code:
//run this to fill ds_queue with random ordered list.
ds_list_shuffle(i_mix);
erf = 0;
repeat (ds_list_size(i_mix))
{
tj = ds_list_find_value(i_mix,erf);
ds_queue_enqueue(item_gen,tj);
erf+=1
}
 

JacobV

Member
Ugh, I really hate to be bringing this back up; but I've encountered a new problem. I'm trying to have the object get more attacks, but when I try to add new ones, it doesn't seem to actually use them, or add them at all. I thought the obvious solution would be to just do ds_list_add and then reenqeue everything, but that isn't working. Anyone have any ideas why this is happening?
 

Yal

🐧 *penguin noises*
GMC Elder
You're a bit vague... do you actually add them to the list before shuffling it? If they're not in the list, they won't get randomly chosen. You could try removing (commenting out) the lines adding the traditional/old attacks and see if it uses the new attacks if it only has access to them, and if not, something is awry with its random selection.
 

JacobV

Member
Here's the code I'm using -

Code:
prmAmount += 1;

ds_list_add(prmSet,choose(
prm_portal1,
prm_spin4,
prm_spin3,
prm_triple1,
prm_triple2));

//run this to fill ds_queue with random ordered list.
ds_list_shuffle(prmSet);
erf = 0;
repeat (prmAmount)
{
tj = ds_list_find_value(prmSet,erf);
ds_queue_enqueue(attackGen,tj);
erf+=1
}
prmAmount += 1 is just to increase the amount of attacks it has for the repeat events.
 

JacobV

Member
Well, once again, it was a mistake on my end. I had to put that code into the object which originally created the DSList, which is confusing because I set it to be a global variable. Oh well; it's working now, and that's all that matters. Thanks for the help!
 
Top