R0J0hound's Forum Posts

  • spongehammer

    Pasting a paster object to itself is no longer permitted by the runtime.

  • You can use a regex expression.

    Using the "test regex" system condition with

    "77,1,6,7,3,17" as String

    "\b7\b" as Regex and

    "" as Flags

    It will only be true if a 7 by itself is in the string, no false positives.

    Here is a reference for regex expressions:

    http://www.w3schools.com/jsref/jsref_obj_regexp.asp

  • The simplest way would be to use the Browser.ExecJS() expression. Although the "^" is different in js, so that will have to be worked around. It is appealing to make your own parser so only certain syntax is allowed as ExecJS allows all of Javascript to be used. The problem is it can be tedious to implement.

    Here's the approach I would take:

    1. Get the text for the formula.

    2. Break it up into a list of tokens (numbers, symbols). Regular expressions can be used here or scanning over the text a character at a time, tokenat isn't suitable. Error checking is done here as well to look for invalid syntax.

    3. Convert the token list from infix notation (1 + 1) to reverse polish notation (1 1 +) as in that form it's simple to evaluate.

    4. evaluate.

    http://en.wikipedia.org/wiki/Reverse_Polish_notation

    There are other ways out there as the topic is pretty vast. You'll end up writing a lot of events (or code) to get something working well.

  • Hi Zetar,

    I finally got around to looking for a solution to this. The formula for the initial velocity from wikipedia is:

    v=sqrt(G*M/r)

    where G is the gravitational constant, M is the mass of the object being orbited and r is the distance. Since we aren't dealing with real distances we can just use 1 instead of G.

    In my tests I didn't use the gravitation plugin, instead I just applied a gravitational force to the planet every tick:

    G*m1*m2/r^2 or

    sun.Physics.Mass*Self.Physics.Mass/distance(sun.X,sun.Y,Self.X,Self.y)^2

    applied toward sun.x,sun.y

    The biggest issue was that box2d units are odd so I had to find a conversion factor, which ended up being about 48.8.

    So my final formula for the planet's impulse was:

    Self.Physics.Mass*sqrt(sun.Physics.Mass/distance(sun.X,sun.Y,Self.X,Self.y))/48.8

    Plugging that into your capx worked, but the orbits aren't perfectly round when using the gravitation plugin.

  • You get the motion because x and z are being changed every time and their values are used in the formulas.

    Here is the reference I used:

    http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/2drota.htm

  • Arima

    Fixed, just re-download the plugins. ".alphaAt" wasn't correctly implemented and the other problem was an issue of pre-multiplied alpha.

  • jayderyu

    The plugin has a .imageUrl expression to get a link to the image and you can then download it using the "invoke download" action of the browser object.

  • When you see "e+21" at the end of the number it means the number is being displayed in scientific notation. So 1.002003004005006e+21 means 1.002003004005006*10^21. Any digits before "e" are the significant digits and with JavaScript numbers you get about 17 significant digits.

    Here is some psuedo code for a function to convert any number to currency format text.

    function format(num)
       if num >= 1000 then
          return format(int(num/1000)) & "," & zeropad(num%1000, 3)
       else
          return str(num)
    end function
  • If you can move an object from one point to another then all that's left is to move up and down as well.

    With this formula as a base for the parabolic motion:

    1-4*(x-0.5)^2

    Here's a capx:

    https://www.dropbox.com/s/cpzg482vpmatb ... .capx?dl=1

    /examples21/leaper.capx

  • I missed a comma there between "runtime" and "constants". 64999966 and 1000000 are constants. By collapsing I mean that 64999966/1000000 is replaced by 64.999966 to avoid needless calculations. The thing to note is the calculation is done before runtime, which is where the issue seems to lie.

    By using a variable between two constants the calculation is all done at runtime.

    And yes by doing the second bit it does give the correct output.

    See the bug report for a capx:

    http://www.scirra.com/forum/constant-folding-percision-issue_topic84055.html

  • Link to .capx file (required!):

    dl.dropboxusercontent.com/u/5426011/bug/bug_constant_folding.capx

    Steps to reproduce:

    1. Run capx.

    Observed result:

    Global variables a and b have different values.

    "a" is set to 64999966 / 1000000 and later reads as 65.

    "b" is set to 64999966*one / 1000000 and reads as 64.999966.

    "one" is a global set to 1 to bypass "constant folding".

    Expected result:

    I would expect both expressions to evaluate to 64.999966 and not just b.

    Browsers affected:

    Chrome: yes

    Firefox: yes

    Internet Explorer: untested

    Operating system & service pack:

    Windows vista sp2

    Construct 2 version:

    r155

  • It appears to be a bug that probably should be reported. This is what CC did which I'm pretty sure C2 does as well: When the events are processed to be usable by the runtime constants in expressions are collapsed. So "64999966 / 1000000" is evaluated and the result is used in place. I suspect some lower precision math is used there. Once past that there is no issue with math in JavaScript because numbers are represented by 64bit floating point values to the best of my knowledge.

    You can also prevent constants from being combined when exporting and previewing by making a global number called "one" with a value of one and use that global in between constants. So your expression would look like:

    64999966*one / 1000000

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can do a smooth transition from side to top in c2 with a formula to rotate a point in 2d.

    http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/2drota.htm

    Here's it in action using pre-rendered sprites for the ships.

    https://dl.dropboxusercontent.com/u/5426011/examples21/shooter_rot.capxr155

  • Just pick the slid_line you want and use it's slid_line.value variable.

  • Yeah with a quick look over the main thing you missed was adding a "-" inside the sqrt. Without it you're calculating the sqrt of a negative number which is NAN. I can look over it better tomorrow.

    What's the formula calculate?