# Best option for choice-based game

Get help using Construct 2

### » Sat Apr 29, 2017 11:09 am

Message: Youtopize can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Hello,

I have been going through the forums for the past few days and I am amazed by the quality of the advice provided here. I am trying to make a choice-based game and have seen some similar examples in the forum (for instance dialog-system_t65873) which have been of great help, especially @Yann. However, I am still unclear of what the best method is, so I am starting this thread.

My intention is to create a game as follows; the player is prompted a question (Q1) such as "You have encountered a bear. What do you want to do?" He is given two possible answers (1a and 1b), which could be 1a="fight!" and 1b="run!". Upon choosing an answer, I would like three things to happen:

1. Feedback is given to the player (for instance, if he chose 1b: "run!", output "player starts running towards the river")

2. After the feedback (on tap or click) the next question is presented, where answer 1a leads to question Q2 and 1b to Q3 (for instance: "You have reached the river, what do you want to do?"). Also, the possible answers to the Question should be displayed (3a:"Keep running" and 3b: "Jump into the river").

3. Points are assigned to 5 categories depending on the answer. For instance, answer 1a: "fight!" would give +2 points to strength and -3 to sanity.

From what I have read, I am guessing that the best option is to have a 2D array of feedbacks and questions and a 2D array with answers and their corresponding scores.

Questions
----------------- Q1
Feedback 1a Q2
Feedback 1b Q3
Feedback 2a Q4...

1a +2 -3 +0 +0 +0
1b -1 +4 +0 +1 +0
2a...
2b...
3a...

There is obviously a mathematical relationship:

Answer 1a (row 1) leads to feedback 1a and Q2 (row 2)
1b (row 2) leads to Q3 (row 3)
2a (row 3) leads to Q4 (row 4)
2b (row 4) leads to Q5 (row 5)

Therefore the relationship is:
Row of Answer chosen leads to row of Feedback and Question +1

The problem is that I do not know how to link the two arrays using Construct 2. I only started with C2 recently, and have not explored all the possibilities yet, but I am guessing it would be necessary to have 3 text boxes, 1 for Qs and 2 for answers, and another layout with a feedback text box.
On click of answer 1a, the scores should be added to global variables and the layout should change to the feedback text box. On another click the Q text box should be updated to Q2 and the answer text boxes to 2a and 2b.
I am guessing I would have to use for loops to connect the arrays, but any guidance on how to do this would be greatly appreciated.

In case this method does not work, how bad it would be to do the game question by question (for approximately 500 questions)? For example, have the same 3 text boxes and writing down as events all the consequences of clicking one answer, in a sort of cumulative sub-events (I think)?

I apologise for the long post, I have tried to keep it abstract, just in case I get the help I need it will also help other people who are trying to find a way to relate the data of two different arrays.

Thank you.
B
5
S
1
Posts: 11
Reputation: 395

### » Sat Apr 29, 2017 11:50 am

Hi @Youtopize,

My suggestion would be to use a 3D array, in the following format:

[Question_1], [Answer_A, FeedbackA, NextQuestion, sanityMod, strengthMod, ...],[Answer_B, FeedbackA, NextQuestion, sanityMod, strengthMod, ...]
[Question_2], [Answer_A, FeedbackA, NextQuestion, sanityMod, strengthMod, ...],[Answer_B, FeedbackA, NextQuestion, sanityMod, strengthMod, ...]
...

Each X field contains all the data for a particular question; Y0,Z0 = question text; Y1,Z0 = answer A text, Y1,Z1 = Feedback text; Y1,Z2 = NextQuestion; Y1,Z3...Zn = stats modifiers; Y2,Z0 = answer B etc...

This keeps all your questions and answers together in one array. NextQuestion points to the X value of the followup question for that particular answer. This makes it a lot easier if you want to change the pointer for the followup question or add new questions to the array.

I would also read up on how to store your array data in a JSON text file and import it with the AJAX object - it's going to be a whole lot easier editing a text file than updating all of those entries directly in Construct.

Hope that helps
B
23
S
9
G
4
Posts: 506
Reputation: 4,429

### » Sat Apr 29, 2017 12:50 pm

@Youtopize,

I've put together a small demo that explains what I described above:

https://www.dropbox.com/s/lajf6pr775paz ... .capx?dl=0

It just loops around between the questions, answers and feedback, but covers the basics. You could simplify this further by shifting some of the repeated actions into functions, but I've left it as is to make it easier to follow what's going on.

Click an answer to select it, click the feedback to progress to the next question.

There are comments in the event sheet to describe what's going on, but let me know if you need more details.
B
23
S
9
G
4
Posts: 506
Reputation: 4,429

### » Sat Apr 29, 2017 2:18 pm

Since the complex (and maybe "correct") way has been explained I will cover the second part of your question.

I hate math, I am terrible at mathematical formula in coding. This includes even things as simple as multidimensional arrays. This is why I was drawn to construct 2, with it I don't have to be good at complex programming logic to make some cool things. Now if I was planning on making a heavy loaded mobile game I might worry about efficient process but short of that I go with what works. I have learned a lot about the maths (and even array use) while doing so.

If "I" was making the game you are describing as a Construct 2 owner. I would do it the long hand way because it would be easier for "me" to understand and debug. My game making time is limited so I would rather be making progress than figuring out the correct way or efficient way if it is not needed for this project... by doing this I find I learn a lot of the correct/proper/efficient along the way.

I would make the three recyclable text boxes and a couple of variables for my holders and stats and I would then make a template (ie basically the first interaction with the 3 choices):

Set text box1 "It was a dark and stormy night, do you wish to go outside?"
Set text box2 "Yeah, sure why not? (Go outside)
Call function setTemp
Set text boxMessage to visible-Set text "Courage +&temp", "Dryness -&temp2"
Wait 1 - Set boxMessage invisible
Subtract temp2 Dryness
Set text box3 "Hells no!" (Quit game)

Function setTemp()
Set temp1 int(random(1-2))
Set temp2 int(random(1-3))
Set temp3 int(random(1-4))
Set temp4 int(random(1-5))

Now all I would need to do is copy, paste and change values for 500 events... would only take an hour or two.
If you were worried about event sheet length on older mobile devices then you could break your events up over multiple sheets but I would not think that necessary for most adventures.

As for the actual clicking process I would spawn invisible sprites under my text boxes that listened for clicks to determine what was the choice was. You could use long buttons as well that contain the text on them, but you would be limited to the Construct 2 ugly button.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
73
S
20
G
8
Posts: 642
Reputation: 9,864

### » Sat Apr 29, 2017 2:29 pm

On second look my example is more for narrated story and less randomized adventure. However, I would still follow that line for a randomized text adventure. I would just build more functions for my choices and results.

Anything that occurs often (run, fight, encounters) would be built into functions that i would call as needed.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
73
S
20
G
8
Posts: 642
Reputation: 9,864

### » Sat Apr 29, 2017 5:45 pm

That is great! Thank you very much @mekonbekon, that is exactly what I needed. I will read a bit on how to use JSON. It does seem more efficient to keep all the data in the same array, with the points for the categories at different depth levels. I will look into how to present the data contained in the array in different layouts, pause the loop to add mini-games and so on, but that seems the best way to approach it.

I see what you mean @chrisfinger. I was going to do the game in a similar way, the one that seems more "intuitive" to me. But I want this project to be easily expanded, so I felt that my way (similar to yours) would be inefficient in the long run. I hadn't thought of the set invisible option, that seems like a good idea for the feedback text box, thank you!
B
5
S
1
Posts: 11
Reputation: 395

### » Sat Apr 29, 2017 5:48 pm

@Youtopize

Glad to be able to help
B
23
S
9
G
4
Posts: 506
Reputation: 4,429

### » Thu May 04, 2017 10:06 am

Hello @mekonbekon,

Thanks again for your help, I am making good progress!
I was wondering if you knew a way to store images in arrays. For example, imagine the feedback included the text and an image. Could I store the name of the image in another Z layer and somehow call it and have the image appear on the layout?
B
5
S
1
Posts: 11
Reputation: 395

### » Thu May 04, 2017 10:22 am

Hi @Youtopize

The easiest way to achieve this would be to have one image sprite and then store all the images as frames on that one sprite.

Give the sprite two animations, one for feedbackA and one for feedbackB, and add the relevant images to those animations: keep the frames in order of the questions.

That way all you need to do is set the frame on the image sprite to the current question and switch the animation depending upon which answer was selected - no need to add extra data to the array, because you're just using the existing data to switch the state of the image sprite.

You could even add an additional animation to show an image before feedback is selected.
B
23
S
9
G
4
Posts: 506
Reputation: 4,429

### » Thu May 04, 2017 10:34 am

@Youtopize

Here's an update to the capx showing what I mean:

https://www.dropbox.com/s/lajf6pr775paz ... .capx?dl=0
B
23
S
9
G
4
Posts: 506
Reputation: 4,429

Next