AllanR's Forum Posts

  • 99Instances2Go

    I have played around with Regex a few times - and it does come in extremely handy in many situations...

    but I really understand very little of the actual syntax or how to build an expression. I usually just google what I am looking for and then copy and paste.

    the trick is usually adapting the code you find to work in C2. A google search for "regex format number" will find javascript code like this:

    function formatNumber (num) {
        return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$&,")
    }
    [/code:dm8cb1vx]
    
    to make that work with C2 you need to take the portion between the forward slashes to be the expression:  "(\d)(?=(\d{3})+(?!\d))"
    (but don't include the forward slashes).
    anything after the second forward slash are the flags (in this case just "g")
    (which means global or look for all occurrences - which is the most common flag).
    then the part at the end is the replace string ("$&,")
    (in this case it means insert the matched string and insert a comma).
    
    so you end up with an action in C2 like this:
    
    Set text to RegexReplace( str(num), "(\d)(?=(\d{3})+(?!\d))", "g", "$&,")
  • if you want to add 1 to GroupFrame every 0.5 seconds, you dont need to create a loop, and slow the loop down...

    you just create an event: Every 0.5 Seconds, with an action: Add 1 to GroupFrame

    (The event sheet as a whole is already a loop... you don't need to put a command like that inside another loop.)

  • Unconnected

    It would really help if you posted a sample capx file and let us make some suggestions.

    You had trouble finding a loop with Wait built in because you can not slow down a loop. That is not what Wait does.

    The code on an event sheet runs really fast - 60 times every second. And the code can execute thousands of commands every tick without any trouble.

    Wait defers the code immediately after it, but the event sheet continues to run at the same speed (blazingly fast). That is why GroupFrame was getting to 25 so fast - before you can even blink.

    I get the feeling you are making this more complex than it needs to be. You seem concerned about having to do too many variable checks, but Construct2 can easily check 624 objects per tick. The problem may be that it does it too fast. That is why you have to structure things in entirely different ways to slow things down.

  • Try Construct 3

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

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

    at line 21 you are checking if animation "felling" is not playing, then set animation to idle.

    well, "felling" is never playing, so the animation is always getting set to idle.

    you should be checking if "felling"&self.a is not playing...

  • Maxum

    the extra digits in the decimals is just how computers handle precision. To fix that you will have to Round(NumInput*100) / 100 (or however many digits you want.

    then you can format the number with one line by using RegexReplace...

    set the textbox to: RegexReplace(str(NumInput),"\d{1,3}(?=(\d{3})+(?!\d))","g","$&,")

    Edit: the only problem with the Regex code above is if there are more than 2 digits to the right of the decimal point, then commas will be inserted there as well.

    In that case, you can use: RegexReplace(str(NumInput),"\d{1,3}(?=(\d{3})+(?=\.))","g","$&,")

    but this version requires a decimal point, otherwise it wont work!

    This would take some more work if you want to zero pad the decimals so there is a consistent number of digits after the decimal point.

  • manukeo

    the player is probably getting stuck on the collision polygon. You can add points to the polygon to help follow along a curve. but it doesn't take much of a bump for the player to get stuck.

    I seem to remember a plugin that would push objects out of a solid, but I am not sure that is the problem here.

  • AnD4D

    text boxes do not dynamically grow, so you must have made one of the boxes bigger than you want. You can change the Wrapping in the properties from Word to Character. If it is set to Word and your text has no spaces, then it will display nothing if the text doesn't fit.

    You could also truncate the text, or edit it in some other way when you insert it into the text box...

    without seeing more about what is happening, it is hard to say...

  • Unconnected

    if the objects ONLY get created or destroyed as a direct response to the player's input, then you don't need to check their status every tick, or ever - unless the player takes action.

    When the objects are created (and given an initial status of 1) you would start the creation animation. You would also need an event: On Animation "CreateObject" Finished to set the status to idle (and show the idle animation if necessary).

    When the player destroys a group you can set the status to 2 and start the destroy animation. Then an On Animation "DestroyObject" finished can remove the object from the screen.

    By using triggers like that, there is no need to constantly check what is happening to the status of an object.

  • Maydie

    when you create objects, the instances can not accessed until the next top level event. (that is why they can be accessed outside the On Start of layout).

    But they can be accessed in the section where they are created, so you could insert them into the array as they are created... (which is what I was doing when the water is created).

  • well, you can download the capx from the tutorial page (near the top, on the left) swipe2.capx

  • Maydie

    yes, it looks like you are calling them correctly.

    However, when the water is created, it is only looking for places that are not water - so it could put water over a tree...

  • Maydie

    when you are adding the trees to the array, you are using their screen coordinate ( tree.x ) ...

    just took another look, and you must have updated the image. try floor(tree.x/32) and floor(tree.y/32)

  • brochiefist

    you could put all the different object types in a family, and then do what Estecka said with a For Each (Ordered) on the family

  • 3DPiper

    I did a tutorial about a touch swiping system a long time ago - I have been meaning to go back and see if I would do things differently now, because I have learned a lot in the last year.

    Take a look, it may help... (look at the swipe2 version): https://www.scirra.com/tutorials/726/swipe-to-change-page

  • Maydie

    Well, I couldn't resist... I made a quick stab at creating lakes. It is VERY random, and does not try to prevent overlapping, or to intelligently place them in any way.

    My son and I were working on random land generation last year, so this is a topic I am interested in. It gets fairly complex pretty quickly.

    What we wanted was to be able to generate land in a similar way to how Minecraft does it. To do that, you need to use Perlin Noise. There is a plugin for C2 that works great: https://www.scirra.com/forum/plugin-noisejs_t93998

    The nice thing about Noisejs is that once you find a setting that you like, you can use that seed number, and get the same results every time, or you can use a random seed, or let people share seeds they like with their friends. Plus you can create infinite layouts - when you have a seed, you just give it the coordinates and you can generate as much of the terrain around that point as you want.

    if you want to see our random terrain, look here: http://www.rieperts.com/games/Goblin/index.html

    Press ESC to regenerate the terrain. You can right-click on dirt to dig into the ground. Press F, G, or H to teleport to the left, middle or right of the map.

    Hold Shift down to run, and press SpaceBar for a huge jump.

    And here is the quick test I did at making lakes from the previous post (does not use the noise plugin): http://www.rieperts.com/games/forum/WaterMapLakes.capx