• 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!

GML choose any worker

S

Swegm

Guest
Hi

does any of you people know how to set this up

obj_workers are created from houses
and if for example i just built a sawmill any worker without a work will go there and start to work

cant find a good way of doing this..

have a nice evening or day wherever you are :)
 
I'd do something like this:

When a worker is created:
Check if there are any worker related structures that need workers and if so, rally the worker there

When a worker related structures is created:
Check if there are and workers that need a work and if so, send them there
 
S

Swegm

Guest
I'd do something like this:

When a worker is created:
Check if there are any worker related structures that need workers and if so, rally the worker there

When a worker related structures is created:
Check if there are and workers that need a work and if so, send them there
yes i thought about something similar, will try this .. thanks ;)
 
S

Swegm

Guest
but hmmm..how will i check for this.. any suggestions?


for example on obj_sawmill

create event
staff = 0


and in obj_worker

step event:
if "any work object" = staff =0

choose any unemployed worker and make him go there ...cant find a way to do this

edit:
of course i know this is not how you write the code :D
 

Rob

Member
The way I do it is have a workplace witha variable called worker which is either an id or noone.

If a worker needs a job and you don't want to use lists or anything like that, you can just cycle through all the workplaces like this;

Code:
with obj_workplace{
   if worker == noone{
      worker = other;
      other.workplace = id;
      break;
    }
}
This will cycle through all the workplace buildings and check if they're free.

You could also add variables like "WoodCutter" or "Miner" and check if each workplace has these set to true or false. You'd use a parent object and make the different workplace objects the children (assuming you have multiple objects).

For movement it depends upon how you have things set up but you'd check first to see if the worker has a workplace to go to, then check if he needs to move to that place and move the worker if needed.

If you use states you'll be able to skip unnecessary checks in your step event.

If workers switch jobs or a workplace is destroyed then you'll have to check for that, reset worker/workplace to noone etc.
 
S

Swegm

Guest
The way I do it is have a workplace witha variable called worker which is either an id or noone.

If a worker needs a job and you don't want to use lists or anything like that, you can just cycle through all the workplaces like this;

Code:
with obj_workplace{
   if worker == noone{
      worker = other;
      other.workplace = id;
      break;
    }
}
This will cycle through all the workplace buildings and check if they're free.

You could also add variables like "WoodCutter" or "Miner" and check if each workplace has these set to true or false. You'd use a parent object and make the different workplace objects the children (assuming you have multiple objects).

For movement it depends upon how you have things set up but you'd check first to see if the worker has a workplace to go to, then check if he needs to move to that place and move the worker if needed.

If you use states you'll be able to skip unnecessary checks in your step event.

If workers switch jobs or a workplace is destroyed then you'll have to check for that, reset worker/workplace to noone etc.
Thanks a lot! this is very helpful!
super great !
 
T

TinyGamesLab

Guest
I'll suggest something a bit different, but in essence is the same.
Why not a 2d array? You can even use 2 ds_lists and manage them by using accessors. This way you can use prebuilt functions. First column would store the workplace, the second the ID of the worker. Both columns can take noone. That way you can loop through the list and see if any worker or workspace are free.
It would look like this:
Noone - Worker 1 ID
Noone - worker 3 ID
Workstation 1 ID - Worker 2 ID
Workstation 1 ID - Worker 4 ID
Workstation 1 ID - Worker 5 ID
Workstation 2 ID - Worker 6 ID
Workstation 2 ID - Noone
 
S

Swegm

Guest
I'll suggest something a bit different, but in essence is the same.
Why not a 2d array? You can even use 2 ds_lists and manage them by using accessors. This way you can use prebuilt functions. First column would store the workplace, the second the ID of the worker. Both columns can take noone. That way you can loop through the list and see if any worker or workspace are free.
It would look like this:
Noone - Worker 1 ID
Noone - worker 3 ID
Workstation 1 ID - Worker 2 ID
Workstation 1 ID - Worker 4 ID
Workstation 1 ID - Worker 5 ID
Workstation 2 ID - Worker 6 ID
Workstation 2 ID - Noone
Thanks as well, my problem here is im not that familiar with arrays, perhaps time to be with this kind of game.. But i think i need to try it first in some simple projects. you have any suggestion for what to do just to understand.. i mean super simple :)
 
T

TinyGamesLab

Guest
Thanks as well, my problem here is im not that familiar with arrays, perhaps time to be with this kind of game.. But i think i need to try it first in some simple projects. you have any suggestion for what to do just to understand.. i mean super simple :)
If you choose to try the array/list path, take a look at:
If you want to go to a simpler path right now, no worries!
 
Top