Best option for choice-based game

0 favourites
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • 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 ) which have been of great help, especially 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...

    Answers

    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.

  • 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

  • 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.

  • 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

    Add temp1 Courage

    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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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 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!

  • Youtopize

    Glad to be able to help

  • 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?

  • 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.

  • Youtopize

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

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

  • Thank you very much! That is great. I had to add a stop animation event because it just kept going through all the frames, I don't know why your capx doesn't have the same problem, but it works perfect with the stop animation event!

  • Youtopize - I meant to comment on that Double click on the sprite to open the sprite editor, select each animation and in the properties window set the Speed to 0. After that you don't need the stop animation event.

  • Hi mekonbekon,

    I figured I would address you directly since you are more or less aware of my project and have been of great help to me.

    I am trying to set up the questions and answers array in Excel and then transfer it to JSON using the framework that you kindly provided. I have found this website to transfer from xls to JSON:

    shancarter.github.io/mr-data-converter/

    shancarter. github. io /mr-data-converter/ (here it is again with a spaces in case I can't send links)

    The problem is that I can't get it to load the array properly on Construct 2. Being able to manipulate the data in Excel would save a lot of time, so I would appreciate it if you could help me.

    Many thanks

  • Hi Youtopize

    I'm not sure off the top of my head what the solution is - could you link to the json that the converter creates? It might just be a syntax issue.

  • Hi Youtopize

    Sorry for the delay in chasing this up. Not sure if you've already solved this or not, but I had a look at the converter that you linked to; it appears that the closest you can get to the right format for C2 arrays is the "JSON-Row Arrays" output option. You then have to convert it to this format, which means adding square brackets around each entry:

    {

    "c2array":true,

    "size":[2,3,1],

    "data":[ [ [ ], [ ], [ ] ],

    [

    [ ], [ ], [ ] ],

    ]

    }

    A potential downside is that it appears you can't convert 3D array data - i'm not sure if there is even a way to store 3D data in an Excel spreadsheet. Should be good for 2D arrays though!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)