• 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 next id in list not returning correctly

G

gameon

Guest
I have several instance arrays, obviously with there own id. With gamepads/keyboard only in mind I wanted to put into "focus" the next id within the list. If the id = noone or last id on the list simply start with the first id on the list, otherwise goto next id. The first part works great without the else statement. So...somewhere within the else statement I am most likely missing something. Each id draws fine above each instance. The list of all id's draw fine so I know this is correct.

I have the following set up:

global.curid = current id in focus;
global.myid = List of all instance id's for the array object;
instance variable: focus (so that only the id with focus can be controlled)

Here's the code:
Code:
// Find all gamepads and return/allow all indexes
gp = scr_gp();

 // Put focus onto next id.
if (keyboard_check_pressed(vk_right) || gamepad_button_check_pressed(gp, gp_padr))
{
  // No id in focus or last id in list in focus
  if ( global.curid = noone || global.curid = ds_list_find_value(global.myid, ds_list_size(global.myid) - 1))
  {
   var get = ds_list_find_value(global.myid, 0)
   with(get) {focus = true}; global.curid = get;
  }
   else
  {
   // id in focus find next id put that one in focus
   var get = ds_list_find_value(global.myid, ds_list_find_index(global.myid, global.curid) + 1)
   with(all) {focus = false;}
   with(get) {focus = true;}
   global.curid = get;
  }
}
 

jo-thijs

Member
I have several instance arrays, obviously with there own id. With gamepads/keyboard only in mind I wanted to put into "focus" the next id within the list. If the id = noone or last id on the list simply start with the first id on the list, otherwise goto next id. The first part works great without the else statement. So...somewhere within the else statement I am most likely missing something. Each id draws fine above each instance. The list of all id's draw fine so I know this is correct.

I have the following set up:

global.curid = current id in focus;
global.myid = List of all instance id's for the array object;
instance variable: focus (so that only the id with focus can be controlled)

Here's the code:
Code:
// Find all gamepads and return/allow all indexes
gp = scr_gp();

 // Put focus onto next id.
if (keyboard_check_pressed(vk_right) || gamepad_button_check_pressed(gp, gp_padr))
{
  // No id in focus or last id in list in focus
  if ( global.curid = noone || global.curid = ds_list_find_value(global.myid, ds_list_size(global.myid) - 1))
  {
   var get = ds_list_find_value(global.myid, 0)
   with(get) {focus = true}; global.curid = get;
  }
   else
  {
   // id in focus find next id put that one in focus
   var get = ds_list_find_value(global.myid, ds_list_find_index(global.myid, global.curid) + 1)
   with(all) {focus = false;}
   with(get) {focus = true;}
   global.curid = get;
  }
}
You did not specify what the issue that you're having is.

Is it that this line:
Code:
   with(all) {focus = false;}
sets focus to false for too many instances so that too few instances are selected?

Is it that you forgot to deselect the previous instance in the true-branch of your if-statement,
so that too many instances are selected?

Or is it that scr_gp changes the indices of global.myid,
so that you can't search for the old id in it and the first instance in the list will always be selected?
 
G

gameon

Guest
I put it in the title forgot to reiterate the specific issue. I have several arrays (26) that each have about 600 items in them. When one is in focus I can scroll down the list, hit a hotkey to get to a certain point in the list...but only when it is in focus. The one that is in focus is kept by: global.curid. All ids are kept in the ds_list global.myid.

I need to find in the list the current id in focus, then get the next one in the list to only put that one in focus. For example, if I have an instance of 100007 in focus the next instance would be 100008 allowing only 100008 to be in focus. (Assume both exists.) Which is supposed to happen with the code above, but isn't working right.

Currently I can put into focus with the mouse any id, then it will move right one with the key presses but never again. If the ID is at the end of the list or begining, in either case needing the first id in the list it puts in focus both the first and last id's.

EDIT:
However, none can be selected when none are in focus with any keypresses.
 
Last edited by a moderator:

jo-thijs

Member
I put it in the title forgot to reiterate the specific issue. I have several arrays (26) that each have about 600 items in them. When one is in focus I can scroll down the list, hit a hotkey to get to a certain point in the list...but only when it is in focus. The one that is in focus is kept by: global.curid. All ids are kept in the ds_list global.myid.

I need to find in the list the current id in focus, then get the next one in the list to only put that one in focus. For example, if I have an instance of 100007 in focus the next instance would be 100008 allowing only 100008 to be in focus. (Assume both exists.) Which is supposed to happen with the code above, but isn't working right.

Currently I can put into focus with the mouse any id, then it will move right one with the key presses but never again. If the ID is at the end of the list or begining, in either case needing the first id in the list it puts in focus both the first and last id's.

EDIT:
However, none can be selected when none are in focus with any keypresses.
I tested it and I can only reproduce 1 of the things you mentioned:
- if the ID is at the end of the list, it puts focus on two instances.
The reason for this I already mentioned in my previous reply: you never set focus for any instance to false in the true branch!

The other issues you're having must be due to some other code.
 
G

gameon

Guest
Sorry about that. That would definitely be it. For some odd reason I swore that line focus = false for the true line was there when reading back my code.

It's still not working even with some rearranging. What's odd though is if I have an id number in global.curid and try to add 1 it ALWAYS gives me 100028 (Which does not exist as an array NOR is it on the list anywhere). I think it's time for some rethinking and start over redo. It may have something to do with where my list was destroyed. The actual object of those instances. Then again I did check if it existed first then destroyed.

I appreciate your time and patience. Will try to post an update a bit later on this weekend.
 
Top