Creating a math platformer, need help with arrays

0 favourites
  • 9 posts
From the Asset Store
Awardkit
$5 USD
Create custom awards and achievement or use the many templates and create your own.
  • 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.

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

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

  • Try Construct 3

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

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

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

  • Here's an idea using an array to store numbers entered on the num-pad:

    mathPlatformer.capx (r91)

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

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

    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?

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

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