• 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 [SOLVED]Choosing Data Structures For Task List

P

Poddington

Guest
Hi Everyone,

I need some advice as I'm going in circles trying to figure out how to do something.

I'm trying to make a task list.

So if I say:

Build this wall
Mine this rock
Haul this rock

The player can check the task list, see what has to be done and assign itself a task. Now there could be multiple characters in the game and the information needed to complete the task would be more than one value.

I don't have the best understanding of data structures, so I may be missing something obvious, but if I use a list, queue or stack I'm only able to have 1 value where as a map allows me to have a key and a value, though no identical keys. I also don't think an array would be sufficient as entries can be removed once completed and unless you use a shift loop to remove gaps the array will get bigger over time.

To throw another spanner in the works, I don't want to be using objects, or as few as possible.

So my question is if someone has an idea of how to approach this please?

Thanks
 

YoSniper

Member
Although what you're saying doesn't give me a lot of information, I think I can make some suggestions to help.

Idea #1
Your queue can be an array of strings like you suggested. But if a task requires specific information, you could provide details in a comma-delimited, or semicolon-delimited format.
For example, you could make a string for building a wall look like:
Code:
"Build a wall;240;160"
which could translate to "build at wall at x = 240, y = 160", but you would need to write some code so that only the first field is displayed (i.e. "Build a wall"). To do that, you would need to familiarize yourself with functions like string_copy()

Idea #2
Make a task object. It would have no sprite, but you could set whatever properties you needed to populate as you created them. Whenever you need to add a new task to the list, you would instantiate a new task object, and just track each task's id in the list. Only major downside to this would be that it would eat up more memory that is likely necessary, but there's a tradeoff between resources and ease of reading.

Hopefully this points you in the right direction. Again, without more visuals or code snippets, I can't be of more help.
 
P

Poddington

Guest
I quite like the idea of a comma-delimited format, as long as the first part says what the job type is the character knows what it will be looking for in the subsequent string.

I've been looking at nested ds lists. A list within a list is the same principle as you propose just laid out differently. I don't know if the sub list position changes as the list shifts size (ie, entries are removed above it) I'm just getting it to work so will keep trying, as it's new territory for me, but you know what.. I think I may end up going with your first idea. I understand this much easier, as it's how I used to make an in-game browser (request the page and use a parser to separate it). Plus it doesn't require objects or additional sub lists.

Idea two is something I already considered, but I'm trying to limit the objects in the game. I'll definitely be trying these ideas out though.

Thanks for the suggestions!
 
P

Poddington

Guest
Hi,

So I used idea 1 to complete the task and it works great. I can now create tasks such as build, haul, attack, mine, craft, etc and the little people in my games will check the task list, assign themselves each a task and complete. I might look in to a more efficient way to do it in the future if problems arise, but at the moment everything runs great at over 400fps so I'm not going to worry about it for now. I'll mark the thread as solved. Thanks for the help YoSniper.
 
A

Ampersand

Guest
Also might be worth noting how you can define a macro

build_wall = 1
build_house = 2
gather_wood = 3

just so you don't have to parse strings and such. An ID system for the tasks will make it easier for when you want to parse it in other situations script-wise.
 
Top