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

Legacy GM Simple Shop system

A

Ashraf Hamdi

Guest
Hi everyone,
How can i make a simple shop? just unlock new characters using in game currency (coins) and use them.
for testing i've a ball object with 10 frames, the image_index 0 is the original one followed by 9 frames for new characters, say i've enough coins to unlock the next 2 characters (frames), how can i deal with such data and save them?
  • character price
  • purchased character (unlocked ones)
  • current character
shall i make an individual object for each character to carry those data or just keeping them as frames and switch between them?
 

NightFrost

Member
Current character can be a simple variable storing a number referencing your current character. Price and purchase data I would make into ds grid. You can save that pretty easily too. If the characters are just visually distinct, there's no reason to make a character object for each, just change the visuals. But if they have different mechanics and behaviors, it would be best to separate their code from each other into different player objects.
 
A

Ashraf Hamdi

Guest
No they have the same behaviors, the only change is the image_index
i just can't understand how ds grid can help me in making shop system, can you please make a brief explanation ? what is the plan? give me an example so i can understand how it works.
many thanks for your help.
 

NightFrost

Member
A ds grid provides a foundation for the shop data. You could use a 2d array too, but ds grid has commands to directly support saving and loading, making it easier. In the grid, each column would present a buyable skin. The first row would be the cost, the second would tell if player has bought it already. Let's say you have 10 buyable skins.
Code:
// Initialize shop ds grid for ten items and two data rows
Shop = ds_grid_create(10,2)
// Set prices for buyables, we use an accessor which is a shortcut for ds grid set and get commands, it works like: [# x, y]
Shop[# 0, 0] = 10;
Shop[# 1, 0] = 20;
// etc...
Shop[# 9, 0] = 400;

// Initialize all ownerships to false
for(var i = 0; i < 10; i++){
    Shop[# i, 1] = false;
}
We could use an enum so we don't need to remember that first row is for prices and second is for bought state, but I'll keep this example simple. Now that the shop ds grid is ready it can be used in various ways.
Code:
// Get the price of third skin (remember, they are numbered from 0 to 9):
Price = Shop[# 2, 0];
// Set sixth skin as bought:
Shop[# 5, 1] = true;
// Check if ninth skin has been bought:
if(Shop[# 8, 1] == true)
 
A

Ashraf Hamdi

Guest
Cool! that's amazing!
can i use ds_map the same way? so i can save it encrypted to avoid changing the ini file by the user ?
 

SnoutUp

Member
Cool! that's amazing!
can i use ds_map the same way? so i can save it encrypted to avoid changing the ini file by the user ?
I would recommend using ds_map instead of ds_grid, because you will be able to setup your unlocks better and won't be tied to any indexes:
Code:
skin = ds_map_create();
skin[? "id"] = "skinRobot";
skin[? "price"] = 100;
skin[? "locked"] = IsSkinLocked(skin[? "id"]);
skin[? "image_index"] = 5;
After this, you can keep them in simple array, ds_list or other ds_map. As for securing the ini, there are ways, but I don't feel experienced enough to answer that question.
 
A

Ashraf Hamdi

Guest
can
I would recommend using ds_map instead of ds_grid, because you will be able to setup your unlocks better and won't be tied to any indexes:
Code:
skin = ds_map_create();
skin[? "id"] = "skinRobot";
skin[? "price"] = 100;
skin[? "locked"] = IsSkinLocked(skin[? "id"]);
skin[? "image_index"] = 5;
After this, you can keep them in simple array, ds_list or other ds_map. As for securing the ini, there are ways, but I don't feel experienced enough to answer that question.
nice!, i understand the ds_map thing (i'm using it to secure save / load score and coins) and i know how to use them as you suggest, but can you please explain how to keep them in other ds_map ?
 
W

whale_cancer

Guest
can

nice!, i understand the ds_map thing (i'm using it to secure save / load score and coins) and i know how to use them as you suggest, but can you please explain how to keep them in other ds_map ?
ds_map_write the ds_map to your main ds_map; this will store the ds_map as a string in the other ds_map. When you need to retrieve it, use ds_map_read; this will convert it from a string back into a ds_map.
 

SnoutUp

Member
can

nice!, i understand the ds_map thing (i'm using it to secure save / load score and coins) and i know how to use them as you suggest, but can you please explain how to keep them in other ds_map ?
Well, I'm doing this for my items:

Code:
skins = ds_map_create();

robotskin = ds_map_create();
robotskin[? "id"] = "skinRobot";
robotskin[? "price"] = 100;

skins[? "skinRobot"] = robotskin; 

ninjaskin= ds_map_create();
ninjaskin[? "id"] = "skinNinja";
ninjaskin[? "price"] = 72;

skins[? "skinNinja"] = ninjaskin;
Keeping ds_maps in ds_maps might complicate the saving. Also, keep in mind that this code doesn't have ds_map_destroy(), because I'm not 100% where exactly should I use it here.
 
Top