Legacy GM [SOLVED] Randomly Generated AI’s

S

Skyler Clark

Guest
Alright so this might be a little hard to explain.

I’ll try my best.

I won’t put you through the explanation of my game, but I basically need to generate unique people with different likes and dislikes. The way I’m thinking about approaching it is to have a list of likes, a list of dislikes, a list of physical appearances, etc. When the person is created, somehow I want one selection from each list to be assigned to this person.

I would normally use some sort of irandom, but in this case I need selections from a list, and not a number.

I know this is kind of a difficult one, but I’m not sure how to approach it. I’m not exactly fluent with GML yet so I don’t know what codes to use. I would appreciate any help you could give me. Thank you!
 

TheouAegis

Member
Selections and numbers are the same thing.

face[0] = white;
face[1] = latino;
face[2] = black;
face[3] = orient;

race = face[irandom(3)]
 
S

Skyler Clark

Guest
This really cleared things up, thank you! I’ll try it
 
S

Skyler Clark

Guest
Okay, now I have a different problem. I’m trying to do what you said but with gender, so male and female. I made a script:

/// scr_gender();

gender[0] = s_ped_male;
gender[1] = s_ped_female;

I put the script in the o_pedestrian (the person) create event.

I went to the o_pedestrian and in the draw event i put:

draw_sprite(gender[irandom(1)], 0, x, y);

When I run the game, the objects rapidly flash both sprites. I know it probably has something to do with where I put the code, but I have to have the draw code in the draw event.

In case you need it, the spawn object is below:


//Create Event:

randomize();

/// Alarm 0 - Create pedestrian
instance_create(672, 384, o_pedestrian);
alarm[0] = irandom_range(4, 10) * room_speed;


//Alarm 0 Event:

/// Create pedestrian
instance_create(672, 384, o_pedestrian);
alarm[0] = irandom_range(4, 15) * room_speed;



Thank you for your time.
 

TheouAegis

Member
When you create the instance, set aside variables inside that instance to hold whatever randomize values you need. You need to generate the randomized values when the instance is created and only when the instance is created. If you put the randomization in a step event or draw event like that, then it will be randomized every single step.
 
S

Skyler Clark

Guest
I moved around the code and managed to get it working! Thank you for your time!
 
S

Skyler Clark

Guest
How would I go about using the item[0] in an if event? Right now I have it as

if like[0] {
//blah blah code in here//
}

I know this doesn’t make any sense so I’m not confused on why it’s not working. I just need to know how to do it. I’ve tried if like = 0 And a lot more and I just can’t figure it out.
 

Relic

Member
Do you mean you want the of code to run only if a certain characteristic/like/dislike has been set to the current instance?

Without knowing your variable names I hope you can understand:

if my_like=like[0]
 

Paskaler

Member
draw_sprite(gender[irandom(1)], 0, x, y);

It's changing rapidly becasue this gets run every frame. Meaning, irandom(i) returns a new random number every frame.

You should assing a variable in instance create event, something like myGender = irandom(1), and then in draw event use myGender instead of gender[irandom(1)]
 
Top