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

GameMaker Stuck trying to figure out how to make a character appear on an inventory screen

O

OriginalGrim

Guest
I want to make it so that the characters status will be displayed in they'er own boxes in the inventory screen and when a character joins the group they will automatically be placed in the lowest number slot closest to the top this is the general idea I had to accomplish this.

Code:
//create
Cinv = 0;

Cslot[0] = noone;
Cslot[1] = noone;
Cslot[2] = noone;
Cslot[3] = noone;
Cslot[4] = noone;
Cslot[5] = noone;

character[0] = Name;
character[1] = Name;
character[2] = Name;
character[3] = Name;
character[4] = Name;
character[5] = Name;

PartyN(N is name) = false

//step
if PartyN = true {
    Cslot{index?] = character[0]
(find the lowest number available and place character into it)
}
// I'm not sure if an array can even equal another array
if Cslot[Number] = character[Number] {
    display that characters status on slot in inventory (draw events I know how to do)
}
Then I want to make it so that if I press E while on the character slot it will highlight the character and then if I press E on another character it will swap their placement as well as making it so that Cinv will reset to zero when it goes over the number of characters currently in the inventory screen, I fell like Cinv may not even be needed at all (was going to use it in a switch event).

I'm new to programming so I don't know if I'm thinking of this properly or if there is a better way to do this I'm trying to do it kind of like in the game tales of symphonia.
 

johnwo

Member
Here's a little object I created to illustrate how this can be done.

Create Event:
Code:
currentIndex = 0; // Value used for selecting a characterIndex
characterSelected = noone; // Value used to swap places of two characters

characterSlot = ds_list_create(); // Using ds_list instead of arrays for convenience
characterNames = ds_list_create();

// Add names to the ds_list called characterNames
ds_list_add(characterNames,"Name1","Name2","Name3","Name4","Name5","Name6");

// Iterate through the list and add the indexes to characterSlot
for (var i=0;i<ds_list_size(characterNames);i++) {
   ds_list_add(characterSlot,i);
}
Step Event:
Code:
var uparrow = keyboard_check_pressed(vk_up);
var downarrow = keyboard_check_pressed(vk_down);
var ePressed = keyboard_check_pressed(ord('E'));
var aPressed = keyboard_check_pressed(ord('A'));

if (uparrow) {
   // Up was pressed
   currentIndex--;
   // Make sure we have a valid index
   if (currentIndex < 0) {
       currentIndex = ds_list_size(characterSlot)-1;
   }
}

if (downarrow) {
   // Down was pressed
   // Here we can use modulus to ensure that we always have a valid index
   currentIndex = (currentIndex+1) mod ds_list_size(characterSlot);
}

if (aPressed) { // aPressed is an arbitrary value used as a condition for adding a new character, here it's when the player presses 'A'
   ds_list_add(characterNames,get_string("Add new character","newName")); // Add "newName" to the ds_list characterNames
   ds_list_add(characterSlot,ds_list_size(characterNames)-1); // Add the index of the newly added name to the characterSlot ds_list
}

if (ePressed) { // Press 'E' to select/swap characters
   if (characterSelected == noone) { // if no character is selected...
       // ...select the character
       characterSelected = currentIndex; // currentIndex is the index of the characterSlot selected
   } else {
       // A character IS selected, so now we swap them
       if (currentIndex != characterSelected) { // Make sure that two different characters are being swapped
           // Make two temporary variables so that we can swap the characters
           var charactedSelectedTemp = characterSlot[| characterSelected];
           var currentIndexTemp = characterSlot[| currentIndex];
           characterSlot[| characterSelected] = currentIndexTemp;
           characterSlot[| currentIndex] = charactedSelectedTemp;
       }
       // Reset the characterSelected variable to noone
       characterSelected = noone;
   }
}
Draw Event:
Code:
for (i=0;i<ds_list_size(characterSlot);i++) {
   var name = characterNames[| characterSlot[|i]];
   if (i == currentIndex) name = " - "+name;
   if (i == characterSelected) name = "<->"+name;
   draw_text(32,32+32*i,name);
}
Use the arrow-keys to select characters, press A to add a new character, and press E to select a character for swapping, then E again (on another character) to swap their places.

This is just an example of one approach, and while functional, it's far from a complete system.
 
O

OriginalGrim

Guest
Here's a little object I created to illustrate how this can be done.

Create Event:
Code:
currentIndex = 0; // Value used for selecting a characterIndex
characterSelected = noone; // Value used to swap places of two characters

characterSlot = ds_list_create(); // Using ds_list instead of arrays for convenience
characterNames = ds_list_create();

// Add names to the ds_list called characterNames
ds_list_add(characterNames,"Name1","Name2","Name3","Name4","Name5","Name6");

// Iterate through the list and add the indexes to characterSlot
for (var i=0;i<ds_list_size(characterNames);i++) {
   ds_list_add(characterSlot,i);
}
Step Event:
Code:
var uparrow = keyboard_check_pressed(vk_up);
var downarrow = keyboard_check_pressed(vk_down);
var ePressed = keyboard_check_pressed(ord('E'));
var aPressed = keyboard_check_pressed(ord('A'));

if (uparrow) {
   // Up was pressed
   currentIndex--;
   // Make sure we have a valid index
   if (currentIndex < 0) {
       currentIndex = ds_list_size(characterSlot)-1;
   }
}

if (downarrow) {
   // Down was pressed
   // Here we can use modulus to ensure that we always have a valid index
   currentIndex = (currentIndex+1) mod ds_list_size(characterSlot);
}

if (aPressed) { // aPressed is an arbitrary value used as a condition for adding a new character, here it's when the player presses 'A'
   ds_list_add(characterNames,get_string("Add new character","newName")); // Add "newName" to the ds_list characterNames
   ds_list_add(characterSlot,ds_list_size(characterNames)-1); // Add the index of the newly added name to the characterSlot ds_list
}

if (ePressed) { // Press 'E' to select/swap characters
   if (characterSelected == noone) { // if no character is selected...
       // ...select the character
       characterSelected = currentIndex; // currentIndex is the index of the characterSlot selected
   } else {
       // A character IS selected, so now we swap them
       if (currentIndex != characterSelected) { // Make sure that two different characters are being swapped
           // Make two temporary variables so that we can swap the characters
           var charactedSelectedTemp = characterSlot[| characterSelected];
           var currentIndexTemp = characterSlot[| currentIndex];
           characterSlot[| characterSelected] = currentIndexTemp;
           characterSlot[| currentIndex] = charactedSelectedTemp;
       }
       // Reset the characterSelected variable to noone
       characterSelected = noone;
   }
}
Draw Event:
Code:
for (i=0;i<ds_list_size(characterSlot);i++) {
   var name = characterNames[| characterSlot[|i]];
   if (i == currentIndex) name = " - "+name;
   if (i == characterSelected) name = "<->"+name;
   draw_text(32,32+32*i,name);
}
Use the arrow-keys to select characters, press A to add a new character, and press E to select a character for swapping, then E again (on another character) to swap their places.

This is just an example of one approach, and while functional, it's far from a complete system.
Going to take me a little bit to go through all of this and apply what's here to what I'm doing but I'm happy I got a reply thanks :)
 
Top