• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Actions based on choices by player

N

nay

Guest
can someone help me understand how i add actions based on options the player chooses? so far my game has dialogue system but the choices are obsolete, if i can understand the logic on how this works, if player chooses option 2 by pressing space from a npc i want some animation to happen accordingly how do i implement this
i have 2d arrays for dialogue and choices
 
Last edited by a moderator:

Yal

šŸ§ *penguin noises*
GMC Elder
Code:
if(player_choose_one_thing){
  //add code based on the choice
}
else if(player_choose_another_thing){
  //different code here
}
else{
 //code to handle all other options
}
 

andev

Member
If you have more than 2-3 options, a switch statement is probably the fastest (and tidiest) option
 

TheouAegis

Member
If you want the choices to accrue overtime, then you will need to store some value. Then with you are going to decide which dialog or options to allow the player to see, you check what the current value is and base it on that. You can have multiple variables handling it. For example, option A could increase your karma, option b could reduce your karma, and option C could do nothing to your karma. However choosing option A would run 1 series of dialog, running option B would run another series of dialog, and option C we run yet a different series of dialogue. So when an option is chosen, you either add or decrease the karma value and then you set a variable to either 0, 1, or 2 to specify which dialog Branch you are a following. Then the next time the dialogue needs to be set, you can check what branch you are on and then also check maybe how much Karma the player has.
 
Top