Creating "lists" and selecting random objects from them.

Hello,


I've run into a headache of a problem with a battle system I'm making in VX Ace; not a full on custom scripted system, just an amalgamation of eventing and pre-made scripts like Yanfly and Luna stuff.  I'm honestly no good with scripting from scratch.


Basically, each turn of battle I want to select a random item from a list, but that list is hand-picked by the player outside of battle.  It's somewhat like a trading card game - the player builds a "deck" with a variable amount of "cards", then draws randomly from it during the battle.


The main problem I have is that the only "random" functionality I'm familiar with is generating a number from X to Y, and I would need to know how many "cards" are in a "deck" in order to determine the value of Y.  Then, of course, I'd have to remove those items without permanently altering the composition of the deck.  Let alone what interface to use that lets a player move things in and out of a list en masse (my current idea is to retrofit Yanfly's Equip Engine and have actors that represent the decks with 20/30/etc equipment slots that you fill with cards).


Really, I'm just looking for whatever help I can get on handling variable lists of items and random selections.  I feel like this probably relies a lot on script calls, which are not my specialty at all.  Thanks for any input on this. ^_^
Have you generated the list already, and you just need to know how to get a random item from it?  Or are you needing help generating it in the first place?


If list is your array of objects pre-picked by the player, obj = list.sample[0] will give you a random item from the list, and list.delete(obj) will then remove the item from the list so it can't be selected next time.  You would possibly need to wrap that in a conditional branch to check !list.empty? to ensure there are items to be selected.


Can't offer any more help because I don't really know what, apart from that, you need help with, and what you've already accomplished.
Ah, I did need help generating the list in the first place, though at the time I meant it in the everyday non-programming sense, like "a shopping list".  It completely didn't occur to me that there could be a built-in List functionality, though now in retrospect I do vaguely remember something like that from programming classes.


It sounds like simply knowing how to manipulate these "lists" would crack this wide open for me.  Do you know of a place where I can look up all of that information?  Trying to Google this stuff just confuses the search engine as much as it's confusing me, since the word 'list' is so ubiquitous. XD
Ruby documentation:


http://ruby-doc.org/core-1.9.3/Array.html



Honestly, I barely understand any of that, but I should be able to make it work with some trial and error.  Thank you.  I see that your examples use "array" as the command word, but Shaz's examples use "list".  Are the two interchangeable?


The only important thing that doesn't seem to be covered here is how to build one of these things bit-by-bit.  That is, all these examples show how to make a new list/array/whatever all at once, but I don't see any that involve adding new items to an existing one.
They, generally speaking and for most popular languages, are used interchangably, though usually languages will stick to one or the other in their documentation.


If you look to the left sidebar on the Ruby documentation, you'll see a list of "methods"-- things you can do to an array. The methods you want are "push" to add, and "pop" to remove. The other methods (other than those two, that is) are named in a fairly self-explanatory fashion.
They, generally speaking and for most popular languages, are used interchangably, though usually languages will stick to one or the other in their documentation.


If you look to the left sidebar on the Ruby documentation, you'll see a list of "methods"-- things you can do to an array. The methods you want are "push" to add, and "pop" to remove. The other methods (other than those two, that is) are named in a fairly self-explanatory fashion.



Ah, perfect, thank you very much!  I appreciate your bearing with me on this, I think I can do what I need to with this information. ^_^

Original thread: https://forums.rpgmakerweb.com/threads/creating-lists-and-selecting-random-objects-from-them.62252/