How do I use math?

0 favourites
  • 9 posts
From the Asset Store
Aliens are invading our planet! Solve the math question, and attack the alien with your laser. Covers addition, subtract
  • Hi!

    I need to now how to use a specific calculation.

    I want to do an action each 1,4,7,10th step etc.

    Now i found out the formula for that would be "3n-2".

    Thing is, i have no clue how to use that in Construct 2.

    Is this possible to do?


  • Hi,

    you need a variable for your n.

    So its 3*"variablename"-2

    Then everytime the event runs add+1 to this variable.

    (in fact thats exacly what you do in your mind with the sequences 3n-2 you add +1 to n on every run.)

  • I see, i never really had math and i kind of know nothing about it.

    I see now that if you calculate 3*1-2 = 1, so indeed 3*2-2 = 4. These are indeed the numbers i am looking for!

    I'm still a little bit stuck though.

    When it comes to math all i get are brainfreezes. I just can't figure it out .

    What i did now:

    IF > commentCheck = 3*commentPage-2 > Do action

    IF > commentCheck = 3*commentPage-1 > Do action, Do Action

    IF > commentCheck = 3*commentPage > Do action, Do Action, Do Action

    commentCheck = The number of comments

    commentPage = The comment page

    I think i'm stuck at the pages.

    If i got 1,2 or 3 comments everything works perfect as mentioned above. Now the problem starts having a 4th comment.

    If i have 4 comments the formulas above don't work anymore if the commentPage is still 1. This makes sense but i am not sure how to switch over.

    Even if commentCheck = 4 but i am still on comment page 1 it should show the first 3 comment.

    The information is always right in my php script no matter the page because i use limit 0,3 if the comment page is 1, i use limit 3,6 if the comment page is 2 and so on.

    So my information is always correct in my script.

    So if i have 4 comments but commentPage = 1 it should read it as 3 comments. Once a user hits the "More comments" button commentPage will be 2.

    My conclusion: commentCheck = commentCheck(4) - commentPage(1). So if i have 4 comments, and i'm on page 1, it will be counted as 3 and it will create 3 comment blocks.

    If i go a page up, the new calculation will be commentCheck = commentCheck(4) - commentPage (2) which results in 2. This is incorrect. Because it should be 1.

    I am really not getting the clue here .

    My code so far:

  • Hi,

    i really dont understand what your trying to many comments

    What i did now:

    IF > commentCheck = 3*commentPage-2 > Do action

    IF > commentCheck = 3*commentPage-1 > Do action, Do Action

    IF > commentCheck = 3*commentPage > Do action, Do Action, Do Action

    your changing the formula here not the variable.

    The formula should stay the same you just need to change the commentPage variable.

    f(x)=3x-2 is a linear function you put a x in and get a f(x)=y out.

    Thats it.

    Never change the parameters (3 and -2) or you will get another function or even a cluster of function if the parameter is a variable itself.


    So maybe you should do something like that:

    on setComments:

    set commentCheck to 3*commentPage-2

    ...........if commentCheck=1--->do something

    ...........if commentCheck=4--->do something

    ...........and so on

    But as i said i dont get what your trying to do with this.

    It sounds like you just want to switch to a new comment page every 3 comments?

  • Yes, i indeed really have trouble explaining my question since i don't understand it myself .

    I indeed want to switch to a new comment page each 3 comments. That's why i have 3 different formula's. I think this is needed because first it will show comment 1,2 and 3. Switching pages should show 4,5,6.

    The reason i think this is the only way is because it's possible to have like 4 or 5 comments. If for example the case is 4 comments it should not trigger the second and third formula after switching to the second page. Because that would create a object for comment 5 and 6, which obviously do not exist if there are only 4 comments. That's why i need to know how to get do a action each 1,4,7 etc.

    Some images:

    This is the result for one comment

    This is how my php script shows how many comments there are

    In the database ( no clue why i shot this screenshot )

    The comment background object is created because of this

    When i added another comment

    Because my php script showed there were 2 comments

    As you can see in the screenshots everything works as planned.

    If i add a third comment the third comment will show up.

    Once i add the 4th comment none will be created. This is where it goes wrong.

    So, if i got 4 comments my php script will result a 4. Just like the 1 and 2 shown above.

    The fact is that i first want to run the formulas for 1,2,3. After clicking the red arrow at the bottom of the screen i want to show comment 4.

    So in fact comment 4 would be on page 2.

    So if i take this image:

    What it should do, if we take 4 comments, is running all 3 actions. Once i click the "next page" button it only has to run action 1 again since that will add up to 4, aka the amount of comments. So if we take 5 comments for example. It again, has to run all 3 actions. After clicking the next page button it will only have to run action 1 and 2.

    P.s. Don't mind all the other info at the php script. This i can assign to each comment block once my issue is solved.

  • I thought about a nice system but its a bit complicated.

    But i just got an easier idea.

    Every comment is a block in your script?

    So just count the blocks. Give them a variable called commentNUmber.

    And a global variable TotalComments

    on comment made add+1 to TotalComments and set the instanze commentNUmber to TotalComments.

    then make a new block at (x=360,y=859+(commentNUmber-1)*133)

    so every comment will create a block 133 pixel under the last block

    then if you klick the downarrow just shift all blocks up(-) 133 pixels.

    on uparrow shift them down(+) 133.

    So you can just "scroll" through them. No need for Pages.


    Its getting late my english is getting worse i am sorry

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've been thinking that way but the thing is that these comments are getting fetched from a database.

    I know i might have high hopes but if this app really works out it could be possible that 1000's of comments will be added.

    There is no way i can pre-load 5000 comments creating 5000 objects. Somewhere i have to cut it off anyways.

    It's also getting late for me i will re-think this trough tomorrow.

    The combo semi-knowledge of Construct 2 and almost no knowledge of math formulas kills it for me .

  • Ok then you need to stick to the three blocks and just load the comments into them from an array(database).

    Thats totally possible with some math magic.

  • Alright! Massive facepalm time !

    I actually created the system before with some bugs. Thought to throw it all around and re-create it ending up in this mess.

    Finally figured it out how to do it. Thing is, i had it almost completely right the first time.

    Anyways this is how.

    Instead of checking how many comments there are for creating the comment blocks i simply check if the comment is empty or not ( duh! ).

    So if comment 1 and 2 are there, it will create 2 blocks. As comment 3 is empty, aka does not exist, it will stop right there.

    Now for the 3 comment limit, that's why i put up a limit in my php script in the first place. This is also how i check if my comments are empty.

    So all there was left was the "next page" button.

    This i've done by:

    ceil(commentCheck/3) =< commentPage > Delete button

    ceil(commentCheck/3) > commentPage > Create button

    Problem solved .

    Thanks for the brainstorming with me .

    This is what it looks like:

    variable l1 and l2 are the limits i send to my php script, so it will only show 3 comments.

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