• 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 Will I use arrays?

S

Swegm

Guest
Hi

making an rts game in style of settlers 3
now i want to jump on to code the ai that decide who will build houses and who will be a woodworker etc.
they will have hunger and thirst and that kind of needs as well.. is arrays a good way of sorting this kind of behaviors?

can someone give me a simple example ?
thanks in advance!

have a nice friday folks!
 

Mario Marin

Member
The AI can use a two dimensional array for the number of worker and the specified need (hunger, thirst, etc.).
and you can use macros for the needs like this:

#macro HUNGER 0
#macro THIRST 1

Worker[No. of worker, THIRST ] = 50;
Worker[No. of worker, HUNGER] = 30;
 
S

Swegm

Guest
The AI can use a two dimensional array for the number of worker and the specified need (hunger, thirst, etc.).
and you can use macros for the needs like this:


#macro HUNGER 0
#macro THIRST 1

Worker[No. of worker, THIRST ] = 50;
Worker[No. of worker, HUNGER] = 30;
oh actually never used macro before.. this is my most advanced game I've ever done :) and i will not give up.. so will try your advice.
 

Xer0botXer0

Senpai
Sweet!
It depends on how you setup your game, personally I haven't made a game that doesn't use arrays. I like being able to iterate between similar instances with ease.
You will see the need as you go on. A lot of the figuring out comes while working on it, eventually I feel like the more experience you have the more likely you are to notice what's needed before the time and the easier it becomes to see how things link together. But you have to work on good routine, good methods.
 
S

Swegm

Guest
Sweet!
It depends on how you setup your game, personally I haven't made a game that doesn't use arrays. I like being able to iterate between similar instances with ease.
You will see the need as you go on. A lot of the figuring out comes while working on it, eventually I feel like the more experience you have the more likely you are to notice what's needed before the time and the easier it becomes to see how things link together. But you have to work on good routine, good methods.
Tänk you! i need this kind of push to keep it going and try.. haha cause i already had countless problems and almost ripped my hair off but now I've solved it pretty much.. the ai will give me a big challenge!
 

TheouAegis

Member
Did Settlers have individual hunger? For an RTS game like that, I'd assume they used a global value.

global.hungry = max(0, floor(global.population * (1 - global.food / global.population / global.rate_of_consumption));

When global.hungry is greater than 0, loop through global.hungry number of settlers and have them draw a hungry icon over their head or whatever.
 

Joe Ellis

Member
I'd definitely use arrays for an rts game, thats how they were all made after all, pretty much any classic game used arrays,
But you really wanna look into using Enums, they're so useful when using arrays,
They're basically global variables, each one being a single digit, or 2, which turns the array indices into words.
I was using arrays for about 2 years before I started using enums, and I'll never go back now,
before I was using certain numbers (2, 4, 5) for certain settings in different arrays, and different types of arrays had different numbers,
I managed to keep track of it all somehow, but WHY do this when you can make a word that IS the exact number you need.
So I just made a few enum groups for each type of array, like a node, an instance, a sound etc.
I've made all these start with an underscore so they dont conflict with common words,
so my basic setup is:

if node[_node.variable] = value
{do this etc}

It might seem abit confusing at first but once you use enums instead of digits your never gonna go back

Btw settlers 3 is a really cool game!
 
S

Swegm

Guest
I'd definitely use arrays for an rts game, thats how they were all made after all, pretty much any classic game used arrays,
But you really wanna look into using Enums, they're so useful when using arrays,
They're basically global variables, each one being a single digit, or 2, which turns the array indices into words.
I was using arrays for about 2 years before I started using enums, and I'll never go back now,
before I was using certain numbers (2, 4, 5) for certain settings in different arrays, and different types of arrays had different numbers,
I managed to keep track of it all somehow, but WHY do this when you can make a word that IS the exact number you need.
So I just made a few enum groups for each type of array, like a node, an instance, a sound etc.
I've made all these start with an underscore so they dont conflict with common words,
so my basic setup is:

if node[_node.variable] = value
{do this etc}

It might seem abit confusing at first but once you use enums instead of digits your never gonna go back

Btw settlers 3 is a really cool game!
so happy for your help!
I'm at the moment when i step up my coding to more advanced so this is very helpful for me !
yeah i really like the style of settlers especially settlers 3 :)
 
Top