GML Update multiple entries in ds_map

E

Ekke

Guest
I'm trying to update multiple entries in a ds_map, namely the value for AGE. The age is supposed to be added to a timer so it changes every time the timer fires. There will also be a "add baby" timer that will add more people to the list.
I'm fairly new to GML and programming in general and I hit a wall with this one, I hope someone out there can assist me here so I can continue with my project.
Many thanks in advance :)


CREATE
Age is supposed to be in weeks currently, will probably change this at a later stage that will make 52 weeks = 1 year 0 weeks.
GML:
people = ds_list_create();

// Men
scr_personmap("John","Jackson","Man",25*52);
scr_personmap("James","Hill","Man",32*52);
scr_personmap("Eric","Strange","Man",33*52);

// Women
scr_personmap("Lily","Jackson","Woman",27*52);
scr_personmap("Rebecca","Southtwig","Woman",27*52);
scr_personmap("Carin","Hill","Woman",18*52);
SCR_PERSONMAP
Script that generates people
GML:
person = ds_map_create();
ds_map_add(person, "First Name", firstname);
ds_map_add(person, "Surname", surname);
ds_map_add(person, "Gender", gender);
ds_map_add(person, "Age", age);
ds_list_add(people, person);
CURRENTLY UNDER KEY PRESS
It generates a person with the age of 1, it's supposed to be 0 and then increase the AGE of all the other people +1. It's not supposed to update the age every time a baby is born, this just a test zone.
GML:
var random_gender = choose(0,1);
if random_gender = 0{gender = "Woman";} else if random_gender = 1{gender = "Man";}

// Add a new person with a random generated name
scr_personmap(string(scr_namegenerator(gender)),string(scr_surnamegenerator()),gender,0);

// Add +1 to AGE to all entries that contain AGE
person[? "Age"] += 1;
 

FrostyCat

Redemption Seeker
I would NOT recommend doing it this way. Instead the map should store that person's birthday in game weeks, then the age can be calculated by subtraction.
 

Yal

šŸ§ *penguin noises*
GMC Elder
ds_maps can be iterated over, but they're the worst data structure for the job if you need to iterate through every member a lot - the use case is "know exactly what member you want". I'd recommend storing a struct in a list instead, and then have all the data in that struct. Since you pick random names from a list, you will have repeats (e.g. Mary Sue and Mary Smith will have the same given-name), so the ds_maps for names (and ages!!) will be useless anyway - you can only have one value per key so the duplicates will overwrite older values.

Also choose works on any data type so you can just have gender = choose("Man","Woman")
 

Nidoking

Member
It's a map per person, not a map of names.

Structs would be the way to go if this is in GML 2.3. Otherwise, maps are a pretty reasonable alternative.
 
Top