How to Set & Update Turns

I have an issue with Unreal Engine 4.

I want to make a variable in my Game Settings that determines the Max Turns depending on difficulty degree (see 1st screenshot) so for my alpha-prototype I want 4 Turns.

I have now 2 problems:

1 - My cards are individual blueprints rather than like the memory game example by Epic because I have no idea how to make the designation of the various cards in one blueprint, and even through digging the Blueprints it was just too complex for me.

So this means a lot of copy-pasta and/or duplicate code, since if I want to deduct 1 turn for flipping a card, I need to include that part in every card. But I wouldn’t mind as long as in the end it would work!

So my problem in this workaround is that I have no idea how to call for round 1 the max turns and continue it on with each card-flip causing to subtract 1 from the current turns.

2 - I have somewhat issues with properly getting one variable to another blueprint. The whole Cast To business is somewhat still a mystery to me XD

Help would be appreciated!alt text

36265-problem_maxturns2.png

Your cast is expecting an object to cast, otherwise it is trying to convert null/empty to something (which will always fail).

You can get a reference to your hud from the PlayerController using the GetHUD node

Pretty much got it figured out now, but somehow my cast to my HUD won’t work. Any ideas?

If I connect the ‘True’ condition straight after the whole ‘Cast’ and ‘Set’ business it works. But with the connection I can click as much as I want, it just won’t move beyond the Cast command.

I am pretty new to UE4 (as you can guess) and am somewhat irritated how I can link the ‘On Click’ from my actor blueprint to the PlayerController blueprint.

And how the casting exactly works. Could you perhaps provide an example or so?

How I have it setup:
BP_GameSettings is an actor blueprint that has Easy, Medium and Hard as 3 possible selections. I made these 3 as texts with collision boxes that are triggered on click.

Easy shall set to 4 turns
Medium shall set to 5 turns
Hard shall set to 6 turns

I need that to set and then of course to display that on the HUD. (which already works, I only have trouble with setting the turns and letting the HUD know about that set)

The reason you need casts is to tell the engine what the real class of the object is, so that you can access the classes properties and functions.

For example, GetHUD returns a base HUD class reference, but your HUD class is CardHUD and you want to access it’s CurrentTurn property. Assuming that CardHUD is derived from the base HUD class (it should be), you would cast the return value of GetHUD to CardHUD, and now the engine will know that it has a CurrentTurn property.

If you lie to the engine though (eg. trying to cast an object that is not a CardHUD as a CardHUD), the cast will fail and you won’t be able to access the properties or functions.