How do I select a certain set of instances? (or how do I group instances into sets)

0 favourites
  • 12 posts
From the Asset Store
A set of retro 16-Bit Neon UI elements to make your menus pop!
  • Good day everyone,

    I have a set of multiple choice questions that I retrieve from a json file.

    I place the questions in a text object and I place the choices (2-4 choices depending on question) in another text object.

    I have about 50 questions with these 2-4 choices for each.

    My question is how do I differentiate between theses choices for each question?

    For purposes of allowing only one choice to be checked per question (think radiobutton)

  • The choices of one question do you put them in one single text object or multiple?

    What you could do is spawn each choice on its own textbox

    Then you add an event:

    on txt touched

    -------Subevent: Text.txt = "Your Valid Answer"

    Or you could also do it style radiobutton:

    Spawn each choice on its own checkbox button

    Then you add an event to compare if it's a valid answer:

    This is if you spawn one single question at a time.

  • All the choices go into a single text object.

    I was actually actively avoiding using the html elements. Wanted to see what I could do without them.

    I know it's easy one question at a time. I'm actually trying to spawn them all together.

  • All the choices go into a single text object.

    I was actually actively avoiding using the html elements. Wanted to see what I could do without them.

    I know it's easy one question at a time. I'm actually trying to spawn them all together.

    Hah, in a single txt is going to be impossible to know which choice they selected, you gonna have to have to spawn each choice in its own Txt object so you can simplify and you will need just one event "On Txt clicked".

    Though if you gonna spawn that many questions and choices you will want to use a sprite font for performance as the Txt objects are very performance intensive.

  • hmmm, I thought there might be some clever way to do it with only 1 text object.

    Did not know that I could use sprite fonts.

    Quick question about sprite fonts. Can I use arabic letters?

  • Quick question about sprite fonts. Can I use arabic letters?

    Sure, the sprite font is like a normal sprite, basically an image containing all the letters. You can build your own sprite font with any language or icons etc... With these great tools.

    Links:

    https://www.construct.net/en/forum/game-development/tools-and-resources-27/sprite-font-generator-v3-64038

    https://www.construct.net/en/forum/game-development/tools-and-resources-27/spritefont-generator-168408

    hmmm, I thought there might be some clever way to do it with only 1 text object.

    I dont say is impossible, I was just trying to simplify your job, most people will go to multiple text object routes. Is there any reason why you would want to complicate yourself that much?

    While a go I replicated my own Txtbox but using a normal Text object so I needed the feature to place the cursor on any letter of the text when clicking on it, I managed to get it to work but it was quite tedious and hacky, I think it was still one issue not sure if I fixed yet, I will have to find the project and check. So in your case, it may be easier as you just need to target just the line of the choice clicked though again why you will want to make that difficult, even if you manage to make it work there are still other questions, for example:

    how will you mark or highlight the answers? so they know which choice they clicked on, etc...

  • Here is a small demo to select a choice from multiple choices in a text to see if it helps you:

    https://www.dropbox.com/s/v95aq328iayegx1/Text%20Cliked%20Line%20.c3p?dl=0

  • Nice idea tarek2! The picking answer system will works correctly as long as you make the choice's string in one line.

  • Nice idea tarek2! The picking answer system will works correctly as long as you make the choice's string in one line.

    Yep, you could add just an instance variable to the Text where you add the choices and save the "Index line number" of the correct Answer and then when they click on any choice you can validate if it's the correct line answer.

    Here is an example, I added:

    1-Highlight the Answer

    2-Validate if its the correct answer

    https://www.dropbox.com/s/z48f0brok2cga8h/Text%20object%20Choices2.c3p?dl=0

  • Good day,

    Sorry for the late reply. Thank you tarek2 for the examples. The expression that figures what where you exactly pressed inside the text box is awesome. Definitely will be using it lots of times.

    For my problem though, I found another solution and I would like your opinion on it.

    I put a sprite (called qContainer) behind each question and its choices. Then I added each question and its choices as children of sprite.

    Then I did this:

    radioBtn is the different choices for each question.

    Is this a good way to do it, or am I going to run into some problems?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • zephirum

    I apologize, I haven't been on the forum for a while and I missed your last post.

    Most probably you fixed your issue so you can ignore this post:

    If that way works better for you and you feel more comfortable then go for it, normally for me what I do as long doesn't affect performance I try to make it as readable as possible as that is number one to finish any project, otherways if you cannot understand your own events then you can get pretty frustrated and it can be difficult to advance and finish it, so go for what you feel more comfortable as in your case it will not affect in any way.

    Though that's what I suggested in my first comment you just added an extra container "qContainer" instead of just adding the choices to a hierarchy to the "Question" directly, is the same thing if you like that way just needed to spawn extra objects.

    For your question:

    -Event = 27 >>>>>>>> Condition = 1:

    (Pick "qContainer" where ID is = variable 1)

    You dont need it as you already picked the "qContainer" in the top event so you can remove it as you dont need to pick it again. The Picking will carry into any subevent.

    -I'm Not sure why you need to pick all the choices as you can just do:

    You can save the answer into the "Answer" txt object in a variable and do just one comparison to check if it's the same.

    On choice clicked: ------------- Check Answer

    But if you need to pick all the choices as you do then you dont need the variable1 & 2

    On Radio_Btn Touched

    qContainer is overlapping Radio_Btn

    Pick all Radio_Btn

    qContainer Pick Own children Radio_Btn

    If you didn't know already you have Families also if you dont want to use the Pick All.

    qContainer Pick Own children Radio_Btn_Family

  • I will keep your instructions in mind. Much appreciation for your help.

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