So I am trying to make a management game, a space station simulator if you will, with potentially hundreds and thousands of customers entering and leaving the station every game day. So my plan of handling this is to first create a persistent object called oManager. Over the course of the game, oManager will continuously spawn instances of this object called oPerson.
The part of oManager that spawns person:
global.dailyflow = 100;
show_debug_overlay(true);
var number_a_day = irandom_range(ceil(global.dailyflow*0.6),global.dailyflow);
trader_base = floor(number_a_day*0.02);
trader_extra = floor(trader_base*(1+global.trader_modifier/100));
tourist_base = ceil(number_a_day*0.1);
tourist_extra = ceil(tourist_base*(1+global.tourist_modifier/100));
passerby_base = ceil(number_a_day*0.53);
passerby_extra = ceil(passerby_base*(1+global.passerby_modifier/100));
shopper_base = ceil(number_a_day*0.25);
shopper_extra = ceil(shopper_base*(1+global.shopper_modifier/100));
mercenary_base = floor(number_a_day*0.1);
mercenary_extra = floor(mercenary_base*(1+global.mercenary_modifier/100));
repeat(trader_base+trader_extra){
with instance_create_layer(0,0,"instances",oPerson){
guy_type = 0;
event_user(0);
}
}
repeat(tourist_base+tourist_extra){
with instance_create_layer(0,0,"instances",oPerson){
guy_type = 1;
event_user(0);
}
}
repeat(passerby_base+passerby_extra){
with instance_create_layer(0,0,"instances",oPerson){
guy_type = 2;
event_user(0);
}
}
repeat(shopper_base+shopper_extra){
with instance_create_layer(0,0,"instances",oPerson){
guy_type = 3;
event_user(0);
}
}
repeat(mercenary_base+mercenary_extra){
with instance_create_layer(0,0,"instances",oPerson){
guy_type = 4;
event_user(0);
}
}
Each oPerson instance decides on how many days he stays, where he would go to and how much money he spends each day, with much more to come in the future. However, the problem I am currently facing is that the game would just crash after about one game day. I think the problem is there are just too many instances and the game just cannot handle it. I tried to create only one oPerson of each type per day and it worked fine. I consider it essential to make each person an instance itself, considering they have to make pretty complex decisions, but I don't know how to make it work.
The game crashes specifically when I click on a button to change room. All of the objects are persistent.