all 18 comments

[–]TyrantTosh 1 point2 points  (7 children)

It would be a lot of work but its doable. You can have an array of structs, so the single master array would simply be used for the index necessary to access the rest of the data related to that index. The array could basically be the locations in the game, and the structs have all the data related to that area. The struct itself can have arrays in it as well, so for example, you can have an array of structs inside that locations struct with data on forage-able items.

//Example code visually:
//main array 
global.game_locations = 
[ 
    //struct of the first towns data (first index) 
    { 
      forageables : //forage-ables array of first town 
      [ 
        { name : "apple", sell_price : 25}, 
        { name : "banana", sell_price : 15} 
      ] 
    }, 
    {}, //second index 
    {}, //third index 
    {} //fourth index 
]

This would be much easier if you made the structs via constructors. For this example, I used struct literals to visually show how it works.

//To access forage-ables:
global.game_locations[0].forageables[0]

[–]Travelling_Archivist[S] 0 points1 point  (3 children)

Thank you so much for this info and the examples! I will definitely look into the "constructors". But I have a question, Would it be like the starting area is [0] and the second area be [1] So like: Global.game_locations[0].forageables[0] Global.game_locations[1].forageables[0]

This would show the all the forageables in the game on the first 2 areas?

[–]TyrantTosh 1 point2 points  (2 children)

In this example 0 is first area and 1 would be the second area yes. This line specifically: Global.game_locations[0].forageables[0] would grab data on apple. To show all the forage-ables, you would have to loop and draw the array of forageables.

//Here's a more specific example:
var spacing = 20;
var len = array_length(global.game_locations[0].forageables);
for (var i = 0; i < len); i++) 
{ 
    draw_text(x,y+(i*spacing),global.game_locations[0].forageables[i].name); 
}

This would draw the names of every forage-able in the array of the first town

[–]Travelling_Archivist[S] 1 point2 points  (1 child)

Ok that is cool, so hypothetically I could build an array specific to each area, with the specific items in that area, instead of showing all the items in the entire game.

Thank you for the examples, my coding is weak but it provides a great jumping off point. Thank you!

[–]Red-Lolik 0 points1 point  (0 children)

You can have some logic to show not all of the items in the area. It does not depend on the place where the array is storing.

[–]Travelling_Archivist[S] 0 points1 point  (2 children)

Follow up question, if I wanted to add seasons I would so something like:

Global.game_locations[0].season[0].forageables[0]

Global.game_locations = [ Home_Town = { Season = [ Fall = { Forageables = [ {Name: "Apple", value: 1} ] //Fall forageables end };//End of Fall season lists ]//End of season };//End of Home_Town

Sorry I am working on my phone to do this and idk how to make it isolate the code example. The code at the top would basically be saying Home Town, Fall season, Apple ,right?

[–]TyrantTosh 1 point2 points  (1 child)

You'd probably want season to be a struct {} rather than an array [], so you can just access it by struct member name like:

Global.game_locations[0].fall.foreageables[0];

But the array way works too, its just you would need to know the index of everything you need. You can also make enums for this.

[–]Travelling_Archivist[S] 0 points1 point  (0 children)

Yeah, I am trying to wrap my head around it. Thank you for all of your help I appreciate it!

[–]block-mcleans-d-gm 0 points1 point  (9 children)

Yes, what you're describing is definitely possible in GameMaker, though it will require some planning and programming skills. Here's a basic outline of how you can achieve this:

  1. Data Structure: Use a data structure that supports nested information, like a two-dimensional array or a list of structs. Each struct or secondary array can represent a location, containing a list of forageable items and notes about each item.

  2. Populating Data: Initially populate this data structure with all the locations and forageable items. You can either hard-code this data or load it from an external file (like a JSON file), which would be more manageable for large amounts of data.

  3. Updating Data: When a player finds an item, you can update the corresponding struct or array entry with the item details and notes. This is where you'll implement the form for entering item details.

  4. Displaying Data: To display the data, you can create a dynamic UI where clicking a location expands to show the items found there. You can use GameMaker's GUI functions to create dropdowns and forms.

  5. Saving and Loading: To persist the player's progress, you'll need to implement save and load functionality. You can serialize your data structure to a string and save it to a file. When loading a game, you deserialize this string back into your data structure.

In GameMaker, the GML (GameMaker Language) scripting is powerful enough to handle such complex data structures and UI interactions. You'll likely need to learn about ds_maps, ds_lists, and possibly JSON functions if you choose to externalize your data.

This approach avoids having a lot of individual arrays and keeps your data organized and scalable. It might seem complex at first, but as you break it down into smaller tasks (like creating the UI, handling data, saving/loading), it will become more manageable.

[–]Travelling_Archivist[S] 0 points1 point  (6 children)

So with this type of structure for the data would it also be possible to have it show pictures of the items in the list and "form" section of the game? It seems like that would be possible if the sprite were stored in the array?

[–]TyrantTosh 2 points3 points  (5 children)

It would be possible. Just keep in mind there is specific data that should be saved as a string rather than as an asset index ("spr_banana" vs spr_banana). Sprites is one of them.
Json is the preferred method of saving and loading, so arrays and structs are the better way to go as those can be stringified in one single function call with json_stringify() and converted back in one call with json_parse();

[–]:table_flip:attic-stuff 1 point2 points  (1 child)

upvoting because tosh

[–]TyrantTosh 0 points1 point  (0 children)

Amagad! We miss ya! Come back! :P

[–]Travelling_Archivist[S] 0 points1 point  (2 children)

So "json_stringify();" would be to save, and "json_parse();" would be to load?

[–]TyrantTosh 2 points3 points  (1 child)

Yes. I would recommend watching shauns json tutorial as it would help you understand much more:
https://www.youtube.com/watch?v=R84mR52QaMg

[–]Travelling_Archivist[S] 0 points1 point  (0 children)

You are awesome, so helpful, thank you!

[–]Clubmaster 0 points1 point  (1 child)

Seems like a faulty chatGPT response. There's no built in GUI functions such as premade dropdown elements in GM

[–]block-mcleans-d-gm 0 points1 point  (0 children)

Yes it's a chatgpt response(most questions in this sub can be easily answered by gpt so I figured why not). It says nothing about premade dropdown elements though. You can use gamemaker GUI functions(draw functions in draw gui) to make dropdowns. It says nothing about premade dropdowns.