Jump to content


Photo

Help with ds_lists


  • Please log in to reply
4 replies to this topic

#1 Arthur Yarbrough

Arthur Yarbrough

    GMC Member

  • New Member
  • 14 posts

Posted 05 March 2012 - 12:54 AM

In my game I have a ds_list, with the sprite_index values of different "cards" shuffled inside. Can anyone give me any ideas on how to make it where when you right click the card deck, you can see a menu (either visual or text) with all the sprite names to select from? I tried using the show_menu function but all it gave me was the sprite's number value instead of the name value making it impossible to tell the sprites apart, and when I changed the code to show the sprite's name, it showed as a string making it impossible to recognize the sprite when clicked. Not to mention the show_menu code I used crashed a lot anyways.

Any help would be really appreciated. :) I've got most of my game engine and mechanics already created but this is a problem that has been bothering me for a long time...
  • 0

#2 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9259 posts
  • Version:Unknown

Posted 05 March 2012 - 01:41 AM

All you need to do is use the sprite_get_name() function to display the name in the menu, but use the actual sprite index everywhere else.

For example, if your ds_list is stored in the variable called "cards", then you can do this:

/* Build the menu string */
displayString = "";
for (p=0; p<ds_list_size(cards); p+=1) {
  spr = ds_list_find_value(cards, p);
  displayString += sprite_get_name(spr);
  if (p < ds_list_size(cards) - 1) { spr+="|"; }
}

selected = show_menu(displayString);

/* Get the selected sprite */
selectedSprite = ds_list_find_value(cards, selected);

Voila :) .

-IMP
  • 0

#3 Arthur Yarbrough

Arthur Yarbrough

    GMC Member

  • New Member
  • 14 posts

Posted 05 March 2012 - 02:01 AM

All you need to do is use the sprite_get_name() function to display the name in the menu, but use the actual sprite index everywhere else.

For example, if your ds_list is stored in the variable called "cards", then you can do this:

/* Build the menu string */
displayString = "";
for (p=0; p<ds_list_size(cards); p+=1) {
  spr = ds_list_find_value(cards, p);
  displayString += sprite_get_name(spr);
  if (p < ds_list_size(cards) - 1) { spr+="|"; }
}

selected = show_menu(displayString);

/* Get the selected sprite */
selectedSprite = ds_list_find_value(cards, selected);

Voila :) .

-IMP


Thank you it's so close to working! The only problem is that it's bundling all the sprites together as one value as in it's not detecting the "|" between them. ): Do you know why this is happening? Thank you, it's so close to finally working I just need to get this one thing fixed. :)

(Idk if it had anything to do with it but I added a -1 as the default value for the show_menu since a default value was missing.)

Edited by Arthur Yarbrough, 05 March 2012 - 02:05 AM.

  • 0

#4 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9259 posts
  • Version:Unknown

Posted 05 March 2012 - 02:10 AM


All you need to do is use the sprite_get_name() function to display the name in the menu, but use the actual sprite index everywhere else.

For example, if your ds_list is stored in the variable called "cards", then you can do this:

/* Build the menu string */
displayString = "";
for (p=0; p<ds_list_size(cards); p+=1) {
  spr = ds_list_find_value(cards, p);
  displayString += sprite_get_name(spr);
  if (p < ds_list_size(cards) - 1) { spr+="|"; }
}

selected = show_menu(displayString);

/* Get the selected sprite */
selectedSprite = ds_list_find_value(cards, selected);

Voila :) .

-IMP


Thank you it's so close to working! The only problem is that it's bundling all the sprites together as one value as in it's not detecting the "|" between them. ): Do you know why this is happening? Thank you, it's so close to finally working I just need to get this one thing fixed. :)

(Idk if it had anything to do with it but I added a -1 as the default value for the show_menu since a default value was missing.)

Sorry; I clearly wasn't proofreading well enough. Where I have spr+="|", it should be displayString+="|" because it's displayString that's being used for the menu, not spr.

And, yes, the default value can be anything you want.

-IMP
  • 0

#5 Arthur Yarbrough

Arthur Yarbrough

    GMC Member

  • New Member
  • 14 posts

Posted 05 March 2012 - 02:31 AM



All you need to do is use the sprite_get_name() function to display the name in the menu, but use the actual sprite index everywhere else.

For example, if your ds_list is stored in the variable called "cards", then you can do this:

/* Build the menu string */
displayString = "";
for (p=0; p<ds_list_size(cards); p+=1) {
  spr = ds_list_find_value(cards, p);
  displayString += sprite_get_name(spr);
  if (p < ds_list_size(cards) - 1) { spr+="|"; }
}

selected = show_menu(displayString);

/* Get the selected sprite */
selectedSprite = ds_list_find_value(cards, selected);

Voila :) .

-IMP


Thank you it's so close to working! The only problem is that it's bundling all the sprites together as one value as in it's not detecting the "|" between them. ): Do you know why this is happening? Thank you, it's so close to finally working I just need to get this one thing fixed. :)

(Idk if it had anything to do with it but I added a -1 as the default value for the show_menu since a default value was missing.)

Sorry; I clearly wasn't proofreading well enough. Where I have spr+="|", it should be displayString+="|" because it's displayString that's being used for the menu, not spr.

And, yes, the default value can be anything you want.

-IMP


I freaking love you this has been annoying me to tears lately! XD Finally! Thank you so much!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users