Ok, so I’m working on a little VR project, and right now I’m trying to make a deck of cards that’ll give you a different card each time you draw from it. However, I’m having a very strange issue that I can’t really explain in one or two sentences. So first I’m going to explain what I’m trying to do with my blueprints, and then explain what’s actually happening. I’ll also post alternate links to these images just in case. (Buckle up kids, this could take a minute.)
https://i.imgur.com/fYsi2Q7.png
(alternate link –> Imgur: The magic of the Internet )
Ok, so here is the beginning of it all. Basically, I just have it so that the deck spawns a card in the player’s hand, instead of picking up the deck. This part works without fail.
https://i.imgur.com/Ufr2qCe.png
(alternate link –> Imgur: The magic of the Internet )
Then I generate a random integer. I set the integer so that it won’t go higher than 51, since there are 52 cards in a regular deck of playing cards. Then I see if the number generated is in an array “removed cards.” If it is, then I go back and generate another number, if it isn’t then I move on to the next step. I also have a text render component above the deck to see what number is being generated (since I can’t really use the debugging tools in VR, I kinda have to make my own.)
https://i.imgur.com/6lkjTqq.png
(alternate link –> Imgur: The magic of the Internet )
Ok, this next part I’m sure someone is going to yell at me for. This is what the next bit looks like zoomed out all the way; just to give you an idea of how much **** went into the next part.
https://i.imgur.com/eAsvnZz.png
(alternate link –> Imgur: The magic of the Internet)
(This is what the previous picture looks like up close.) So first off, there’s a couple of nodes here that I forgot to put in the screenshot. I have a name array of 52 elements (each one being a different card) Just before this mess of wires, I have a “get cards” node, and a “get index” node. I plugged the “get cards” node into both the “get index” node, and all those == nodes you see there. I also plugged the aforementioned random integer node into the “get index” node. So what it’s doing (or at least what I think it’s doing) is pulling a random element (or card type) from the “cards” array based on what random integer comes up. After that, I’m performing 52 checks to see which card name got pulled from that array. When it finds a match, it sets 2 integer variables into the card I spawned earlier: A “suit” variable, and a “#”(number) variable.
https://i.imgur.com/Y4pjFbZ.png
(alternate link –> Imgur: The magic of the Internet )
Ok, so after it does all that stuff, I have it perform a custom function from the card_bp that it spawned earlier which sets the picture on the face of the card (I’ll go over that in a second.) Then it takes the previously generated integer, and adds it to the “Removed Cards” array, and removes the corresponding index from the “Cards” array. Then if there’s nothing left in the “Cards” array it just destroys the whole deck altogether.
OK, so that’s what’s in my deck_bp thus far.
https://i.imgur.com/ylQnGiP.png
(alternate link –> Imgur: The magic of the Internet )
This is what’s in the “Set Card Picture” function that I was talking about. It takes those “Suit” and “#” variables that I was talking about earlier, and creates a dynamic material out of a material that uses those variables to map out the texture below.
https://i.imgur.com/E2r7lIZ.png
(alternate link –> Imgur: The magic of the Internet )
https://i.imgur.com/cvjl64u.png
(alternate link –> Imgur: The magic of the Internet )
I also have another thing set up in this function. I have a text render component on my card_bp as well, it’s set up so that it says the card’s number and suit based on the “Suit” and “#” variables. But again, this is just for debugging purposes.
Ok, so that’s what I have set up and my thought process behind it. Now here’s what it actually does.
Every time you draw a card, one of 2 things will happen. You will get one of two kinds of cards:
https://i.imgur.com/kt4MAz5.png
(alternate link –> Imgur: The magic of the Internet ) (also I’m sorry about the weird angles, it’s hard to screenshot in vr T~T )
The number indicating the random integer always changes with this, but this card repeats a bunch. It always says “Text” over the top like that, and it’s always ace of hearts. But if you don’t draw that, you’ll get this one:
https://i.imgur.com/LLuta9X.png
(alternate link –> Imgur: The magic of the Internet )
(this isn’t to say that this card is always the 3 of clubs, the face and text on this card actually function perfectly) Now at a first glance, there’s really nothing wrong with this. The image on the card says 3 of clubs, and the text above it does too. However, there is one really weird inconsistency. The floating number above the deck is supposed to be indicative of the random integer that we generated earlier, which also was supposed to determine which card we picked from the “Cards” array. But look here:
https://i.imgur.com/uNBa4Ug.png
(alternate link –> Imgur: The magic of the Internet )
Element 18 in the “Cards” array is not the 3 of clubs, but in fact the 7 of clubs. So why the toot did I get the 3 of clubs?
So to recap on everything, I’m trying to make a working deck of cards, but I forked up somewhere super hard and I have no idea where or how or who or where. There’s a lot of **** here, if you need me to re-explain something please ask, cause I really want to figure this out. Any and all input is greatly appreciated.
UPDATE: I figured it out, I just had to put an “is valid index” check after that first branch.