I am making a cartomancy game. I seperate the 4 suits and the 13 numbers to get random item. So what I am trying to do is to make a graph that define the combinations of suit and number then give results but have totally no idea how to do it. I am an unreal beginner and really hope to get some help, thanks a lot.
It looks basically ok, and you didn’t explain what the problem is.
But I’m thinking it might be here
because that random node has a lot of wires coming out of it. How the engine works, is it will call the node for each wire, so you’re probably getting a lot of weirdness?
The answer is to call the random node once, and put the result in a variable, and then connect all those wires to that variable.
thanks for your reply, and as you said it works just fine for that part. I’m not sure did I indicate the obstacle well, but what I want to make is to generate events base on different results of the card. The green wires are my test for doing that.
This is my thinking process:
1.get the generated index from the random node by using equal node
2.and when the card generated is a specific suit
3.then call event.
In gameplay, the strings are printed, but differs from what I thought, I don’t see the pattern at all
I am sure this is a silly way, and this is what I mean by I have totally no idea how to do this.
@yonelaine In my opinion, to avoid too many branches/manual checks and all those nodes that create confusion. You could create a map dictionary, an indexed collection of data under one or more specific keywords. The unique keys could be the suits of the cards, so that to each suit you can associate the values ​​that the suit can assume, its material, etc.. If I understand correctly what you are trying to do.
It’s a common gotcha with randoms:
- the random node is evaluated every time it is accessed
- the Update of the TL fires ever frame
- this means you’re generating 60 (more, because you access it many times) different values every second
How to get the specific result of random item from array?
You can’t have both. What you can do:
- generate the random once, before the TL starts, before setting text
- store the result in a variable
- instead of sampling and re-evaluating the random many times, use the cached value in that variable
That’d be the very 1st thing to address, there may be more.
@Cykablatta @Everynone Thanks a lot guys! I get a big inspiration from your reply. And I have one more question now: Is there a smarter way instead of repeating the highlighted part for 52 times?
Here is what my graph now look like
Which part would that be? And, yes - if you feel like doing something 52 times, there’s probably a way not to. Usually with functions, macros, loops.
- “Why spend 10 minutes doing it manually when you can spend 10 hours automating it?”
That’s true. I’m not sure which one is suitable in “functions, macros, loops”, I guess I should look it up. Thanks. And by highlighted part, I mean the part in comment box. And by repeat I mean copy and paste the nodes with changing integer value.
@yonelaine I think using a key as the seed type (so name/string) rather than an integer key can help. I think it also depends on how/when the search in the map is performed. If your goal is to get all the values ​​in the map at once, I don’t think it changes much. I had suggested the map to you above all to avoid all those sets, etc. So if you wanted, at a later time, to add under a key more different data at the same time for each possible card, you can use as “value” of the map, not only an entry but an entire structure, which can host multiple types of data and which can be collected in totally different ways between them. (a value will be collected as a single, another as an array etc.)
I didn’t understand, of course if you are going to copy and paste the same code but with a different index, there is an alternative way to obtain that result but in a more efficient way, for this you just need to use the same map dictionary that you created, and iterate on it with a “for each loop”.
(Custom Event) - Get Map - “Keys” (array) - “for each loop” - Find Map
A short outline of how it should work, so automatically for each key, it finds all the values ​​registered under it. Then, you can also set the elements as variables to simplify, operations like branches/sets etc..
@yonelaine
@jetboy_hrn1990 I think the “shuffle” node randomizes the indices and therefore the order in which the elements appear in the array. To take a random element, there is a node called “random”.
Shuffle works great if you want no repetitions. How to tackle it depends on what the end goal is.
@Everynone So shuffle also allows you to take? Or do you still need another node?
That’s what it does, you nailed it. But we don’t know what needs doing:
- if you want to fetch one random element - use the
Random
node - if you want to get many elements in random order, and with no repetitions -
Shuffle
→For Loop
→Get
Cool! I didn’t know that! My thinking was limited because of Magic The Gathering!