GM:S 1.4 [SOLVED] Randomly Generated AI’s

Discussion in 'Programming' started by Skyler Clark, Nov 24, 2018.

  1. Skyler Clark

    Skyler Clark Member

    Joined:
    Jan 5, 2018
    Posts:
    29
    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!
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,876
    Selections and numbers are the same thing.

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

    race = face[irandom(3)]
     
  3. Skyler Clark

    Skyler Clark Member

    Joined:
    Jan 5, 2018
    Posts:
    29
    This really cleared things up, thank you! I’ll try it
     
  4. Skyler Clark

    Skyler Clark Member

    Joined:
    Jan 5, 2018
    Posts:
    29
    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.
     
  5. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,876
    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.
     
  6. Skyler Clark

    Skyler Clark Member

    Joined:
    Jan 5, 2018
    Posts:
    29
    I moved around the code and managed to get it working! Thank you for your time!
     
  7. Skyler Clark

    Skyler Clark Member

    Joined:
    Jan 5, 2018
    Posts:
    29
    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.
     
  8. Relic

    Relic Member

    Joined:
    Jun 27, 2017
    Posts:
    719
    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]
     
  9. Paskaler

    Paskaler Member

    Joined:
    Jul 4, 2016
    Posts:
    315
    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)]
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice