|
Post by Gary on Sept 6, 2018 20:51:11 GMT
Hello I am trying to make it so that i dont have to end turn to begin the game. Do you have a way to make it so that it randomizes who plays first and draws some cards? thank you by the way for this tutorial - i am working through it right now and it is very informative. Gary
|
|
|
Post by Admin on Sept 7, 2018 13:14:33 GMT
Of course! To randomize the player who goes first, try using something like: Random.value It will generate a value between 0 and 1 so you could say something like if that value is less than 0.5 it will be the first player's turn, and otherwise would be the second player's turn.
Next, I will just point out that you aren't actually needing to press "End Turn" to begin the game. The game has already started at the very beginning with the human player as the first player. The problem is that we have only connected the "Draw Card" action as a reaction to "changing" a turn. On the very first turn though, we haven't actually changed a turn - it is just whoever's turn it is. You could try applying a change turn action to cause it to be whoever's turn you want, and then the draw card action will occur, or you could just make the draw card action respond to some other action in addition to changing turns, such as a coin flip action (to determine who goes first) or any other kind of action that would happen at the beginning of a game - such as how Hearthstone gives you a preview of your starting hand and allows you to swap out your cards if you don't like them.
|
|
|
Post by Gary on Sept 9, 2018 18:58:06 GMT
Okay thank you - You mentioned it starts at the local player's turn - how would i make it so that it actually starts at the opponents player's turn though. It would not make sense to make it automatically end turn but to actually start the turn on the opponent's turn somehow.
|
|
|
Post by Admin on Sept 10, 2018 0:32:03 GMT
Take a look at the "Match" script - the "currentPlayerIndex" indicates whose turn it is, with an index of zero for the local player and an index of one for the computer player. Then take a look at the "GameViewSystem", for better or worse, I have some temporary code there inside of the "Temp_SetupSinglePlayer" method that shows how I know what kind of player is assigned to each index. You could assign the match's currentPlayerIndex field at the same time as you assign its player's modes. Anything done directly like that would be just the way the game is configured when it begins. Otherwise, you could perform the configuration as some sort of game action so that other systems can respond accordingly.
|
|
|
Post by Gary on Sept 12, 2018 17:12:47 GMT
thanks for the help and clarification
i tried adding this to gameviewsystem and creating a gamestart system / action
void raisestartrequest() { container.addreaction( new gamestartaction(true)); }
the gamestartaction works cause i see it loggged in my console but the gamestartsystem which has the observer gamestartaction doesnt get called...
the gamestartsystem is in gamefactory so not sure why it wouldnt be listening for the action that gets called
|
|
|
Post by Gary on Sept 12, 2018 17:15:53 GMT
What is the difference between addreaction and perform ?
|
|
|
Post by Admin on Sept 13, 2018 14:15:48 GMT
You may want to re-read lesson 4, Action System theliquidfire.com/2017/09/11/make-a-ccg-action-system/But the general idea is that you use Perform action when the game is in an idle state, to start a new sequence of events. You use AddReaction during an existing sequence of events at notifications sent by the Action System. Here is an exerpt from that lesson that is particularly relevant: The “AddReaction” method is what will allow the observers of our action notifications to treat the action as a trigger for a new event. Note that this should only be used directly within an appropriate notification handler such as an actions “prepare” or “perform” keyframe notification, or from a system event notification like the “deathReaperNotification”. Note that the “beginSequenceNotification”, “endSequenceNotification”, and “completeNotification” notifications are NOT appropriate places to add triggered reactions. Attempts to add a reaction at unsupported times could lead to crashes or other unexpected consequences.
|
|