0 Reputation

# Creating a math platformer, need help with arrays

Forum Home > Construct 2 General > How do I....?
Author
Topic Search   Topic Options
436 Rep
Post Options    Quote  Reply Topic: Creating a math platformer, need help with arrays
Posted: 21 May 2012 at 3:57am
Hi all! I had one thread previously, and you were all incredibly helpful with that one, so I've returned for more excellent advice.

I searched through the tutorials in the sticky and on the main website and although there is an Arrays tutorial, I'm not exactly sure that arrays are what I need. (they seem a little bit verbose for what I need...?)

What I need:

I'm creating a math platformer, and there will be an event where a player has to solve a math problem to proceed, and I am wondering what the best way to generate problems would be? Is there some way to procedurally/randomly create them? Should I create a list and then pull one from the list? How will C2 know if the player has entered the correct answer (with the numbers on the keyboard)?

I know this probably sounds pretty basic to some of you, but I am new to algorithmic reasoning and these problems kind of stump me.
5,545 Rep
Post Options    Quote  Reply Posted: 21 May 2012 at 7:54am
I think the solution really depends on the complexity of the math problems you have in mind. Will they be very simple addition or subtraction problems, perhaps for children?

If they're advanced math problems, you may need to get into some lightweight math parsing or perhaps rely on JavaScript's eval function via the CallJS plugin (it's probably safer to use an external JavaScript parser like the this one).

For simpler math problems, you can probably just create 2 random numbers and randomize an operator with something like the following:

x = int(random(1)) + 10
y = int(random(1)) + 10
operate = choose("+", "-", "/", "*")

MathString = str(x) & operate & str(y)

You can store a series of such strings within your array, then when you choose a random element out of the array, solve it using a special event sheet.

That'd be my own idea for a solution. Perhaps others may have better ideas.
Check out Nibble in the HBGames Build and Win Construct 2 Contest!
436 Rep
Post Options    Quote  Reply Posted: 21 May 2012 at 4:59pm
 Ugotsta wrote:You can store a series of such strings within your array, then when you choose a random element out of the array, solve it using a special event sheet.

Yes, it's math for children in 4th grade, so this sounds good. Could you explain how you would go about creating a solution event sheet? So if the prompt ends up being

12 * 2 = ?

How does the user input the answer? Sorry if this is all very basic stuff.
3,012 Rep
Post Options    Quote  Reply Posted: 21 May 2012 at 6:57pm
well since its a platformer game why not make the player input the answer by jumpin on the platform with the right answer? or jump on a 10 platform twice and a 1 platform 4 times to get 24?

Or you could always just take the simple approach and make a text input box appear and they type it
436 Rep
Post Options    Quote  Reply Posted: 21 May 2012 at 9:57pm
 aridale wrote:well since its a platformer game why not make the player input the answer by jumpin on the platform with the right answer? or jump on a 10 platform twice and a 1 platform 4 times to get 24?Or you could always just take the simple approach and make a text input box appear and they type it

The problem with using the text input box is: The game is locally multiplayer, and only one player will have to enter in numbers... The other player needs to be able to input controls while the numbers are being entered.
9,525 Rep
Post Options    Quote  Reply Posted: 21 May 2012 at 10:44pm
Here's an idea using an array to store numbers entered on the num-pad:
mathPlatformer.capx (r91)
436 Rep
Post Options    Quote  Reply Posted: 21 May 2012 at 11:47pm
 ramones wrote:Here's an idea using an array to store numbers entered on the num-pad:mathPlatformer.capx (r91)

That's just about perfect. Thank you so much. What is the difference between push back and push front? I am imagining the array as a line of blocks, and push back means adding elements (blocks) from the right side, and push front is adding elements (blocks) from the left side. Is that correct?

Edit: Man, this just makes sense. I freaking love C2.

Edited by nihakue - 22 May 2012 at 12:01am
436 Rep
Post Options    Quote  Reply Posted: 22 May 2012 at 12:37am
So here's the capx with ramone's code implemented. (use wasd to control the green block, but the camera follows the little dude, so use arrow keys to move him around)

The orange block is the "challenge"

http://dl.dropbox.com/u/11790413/Final_Project.capx

Do 'or' blocks not work with key presses? so I could do :

-'on 1 or num 1 pressed'

Or should I just create a separate event?
9,525 Rep
Post Options    Quote  Reply Posted: 22 May 2012 at 2:44pm
Yeah you can use 'or' with the keyboard triggers. BTW an easier way to reset the array, instead of the loop I used, is:
input->Set size to (0,1,1)

 Forum Jump -- Select Forum --  Arcade  Construct 2 general  How do I....?  Your Creations  Education  Bugs   - Closed bugs  Plugins for Construct 2  Javascript SDK development  Open Topic  General game design  Tools/resources  Website issues  Help Wanted  Construct Classic Discussion   - Help & Support using Construct Classic   - Your tutorials & example files   - Your Creations   - Completed addons   - Work-in-progress addons   - Construct engineering Forum Permissions You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot delete your posts in this forumYou cannot edit your posts in this forumYou cannot create polls in this forumYou cannot vote in polls in this forum