How do I structure functions

Just started using Construct 2? Post your questions here

Post » Tue Aug 16, 2016 7:28 pm

Good Afternoon,

I just recently bought Construct2 and am banging my head against the wall. I am used to writing code such as C# and have been struggling with the Event based system in Construct.

To train myself, I am creating a trivia based game but am really confused on how best to implement the functions/loops.

Here is my basic setup:

- I have a two dimensional array with a series of questions and answers. Each question has an associated correct answer.
- I would like to display a random questions and a multiple choise consisting of the correct answer and three incorrect answer chosen from answers to other questions.

For example) Question 1 - Answer choice 1 (correct answer from question 2), Answer Choice 2 (correct answer to question 1), etc, etc.

How I have it structured now:
- I have a layout with a test (questions) and four answer buttons.
- I have the two dimensional array that contains all the question/answer pairs.
- I have a function that generates a random number and displays the question.
- I need to figure out how to create a structure that would allow me to select the correct answer and three incorrect answers (from the other questions) and display them in random order across the 4 buttons. - this is where i am stuck.

Bonus question: I don't know if this is a reasonable way to accomplish this.
- To remove an already displayed question, I have created a second array as a copy of the original and when a question is chosed, I am removing it from that array. That way when i generate the next random question, the previously used question will not be available to be chosen.

- I then am pulling the incorrect answers from the original array so i don't run out of incorrect answer options.

Anyways, I could do this quickly in C#, for example, but am banging my head against a wall here. Any help would be appreciated!
B
3
Posts: 3
Reputation: 181

Post » Tue Aug 16, 2016 9:11 pm

I'm no programmer but in C2 I would start out by doing this :

Choose a random number for question, if question Q is 5,0 in array then A = 5,1 (or simply 5, the x-coord of the question and answer)
Generate a random number for B probably use floor(random(array.total)), check the outcome does not equal A then use that for B.
Do the same to generate C, making sure it is not the same as A or B, and for D make sure it does not match A, B or C.
Then you have 4 answers A, B, C and D that are numbers i.e. 5, 6, 1, 22 that match the co-ords of the array, where A is the correct answer and B, C and D are random answers.
Then assign A, B, C and D randomly to 4 numbers 1, 2, 3 and 4 that match the answers boxes.

There are probably better ways of doing this but that would be my initial approach.
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Tue Aug 16, 2016 9:32 pm

Thanks for the reply!

I have this part currently:
question Q is 5,0 in array then A = 5,1


I understand this part, but unsure how to structure that reasonably well in C2:
check the outcome does not equal A then use that for B. Do the same to generate C, making sure it is not the same as A or B, and for D make sure it does not match A, B or C.


and not clue on this part in C2:
Then assign A, B, C and D randomly to 4 numbers 1, 2, 3 and 4 that match the answers boxes.
B
3
Posts: 3
Reputation: 181

Post » Tue Aug 16, 2016 10:21 pm

This is verrrry basic and longwinded and can probably be done faster by passing the same parameters through a function or something, but for the structure...and a quick 5 min job...something like this works as far as generating 4 random answers from the array, I just set it up and tried it. Also I guess it answers your original question of how to set up functions with the structure they use in C2 :

Image
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Tue Aug 16, 2016 10:33 pm

Oh and to grab the actual text value from the array it'll be something like 'For Answer A Text Box > Set text to array.at(AnswerA)' where AnswerA is the global variable i.e. the location in the array that was randomly generated.

And the .capx https://dl.dropboxusercontent.com/u/495 ... squiz.capx
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Tue Aug 16, 2016 11:20 pm

Awesome. Thank you. I think you got me where i needed to go.
B
3
Posts: 3
Reputation: 181


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests