Fengist's Forum Posts

  • Just posted this reply elsewhere. See if this fixes it:

    construct.net/en/forum/construct-3/general-discussion-7/ajax-changed-recently-not-140404

  • Oh, and once you have it all running and working, delete the two lines of error reporting...

  • First of all, the

    Access-Control-Allow-Origin: *

    is a huge security hole. It means, anyone, anywhere can run that php file and can Post, Get, do whatever they wish to it. The whole point of CORS and AJAX is to limit who can call it and what they can do.

    Try this code instead:

    error_reporting(-1); // reports all errors
    ini_set("display_errors", "1"); // shows all errors
    
    if (isset($_SERVER['HTTP_ORIGIN'])){
     $http_origin = $_SERVER['HTTP_ORIGIN'];
    }
    else
    {
     die();
    }
    
    header('Access-Control-Allow-Methods: "POST"');
    
    if ($http_origin == "https://preview.construct.net" || $http_origin == "https://www.mysite.com") {
     header("Access-Control-Allow-Origin: $http_origin");
    }
    

    Change 'mysite' to the URL of your website.

    This is a chunk of code I save as 'header.php' and

    include "header.php"
    

    in all of the php files I want to access with AJAX.

    Access-Control-Allow-Origin: $http_origin

    determines who can access the script and

    Access-Control-Allow-Methods: "POST"

    determines what they can do.

    The first two lines are for error reporting so you should see if the script crashes.

    Now, that being fixed.

    If you are still running http and not https that's likely the issue.

    Chrome in particular will block access from a secure site to an insecure one. You'll notice this because a little shield icon will appear in the top right of Chrome. When you hover over it, it will tell you that the site is trying to run insecure scripts and it blocked it. You can click on that shield and unblock the site but you have to do it each and every time.

    Finally, I recall reading somewhere recently that AJAX blocked requests to non-https sites. If you haven't gotten your certificate yet, now is a good time.

    If you need a secure website, I personally use interserver.net. $5.00 a month and that includes a free cert.

    That's my guess.

  • or 175+random(0,20)

    newt showoff...

  • Elegant is a word used by those who get paid entirely too much to sit and think of ways to make science appear attractive to the artistically inclined mind. For the rest of us, functional replaces elegance.

    LayoutName = "X" -> Call Y

    If it ain't broke, don't fix it.

  • In a very general sense:

    Have your enemies raycast toward the player.

    If the player is hit with the raycast, store the x,y location of the player in that enemy's instance variables and shoot.

    If the raycast then misses the player, have them move toward the x,y location and raycast again.

    If that raycast misses, you can have them start wandering around and searching or return to their original location.

  • I'm not positive but I don't think the arcade is set up to use C3, only C2. Last I read they were planning on reworking the arcade.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Set the angle to random(175,195)

  • Bump

    Getting annoying errors because the JS above is running regardless of the layout that's visible and it only affects one layout.

    So again, anyone know of a way to tell JS to only run when a specific layout is open?

  • And I just did a test with a progress bar where I subtracted an amount from a global variable every 0.5 seconds and set the progressbar.value to that amount. It worked as intended whether I ran in preview or remote preview.

  • Ok, what I would do is to add a global text box somewhere and have it constantly display the actual value for HP_Pet. Right now, your hp bar is showing a percentage. You need to see the actual value of HP_Pet when the game loads and when you move just one space. Something is either changing how fast it makes that calculation or it's performing that calculation multiple times. Until you know the actual amount of HP_Pet and how much 1 move subtracts, you're just guessing.

  • Nothing was remembered? Do you mean that it didn't change the formula to Subtract (HP_Pet * .01) from HP_Pet???

    This sounds strangely like a browser caching issue.

    When you load up the remote preview in Chrome hit Ctl-r and f5. That forces Chrome to reload the page.

  • Even though this is a serious necro I guess it's time to answer it.

    You can accomplish this with CSS. Unfortunately, the text element does not allow you to directly input CSS and change it so you'll have to get really creative with CSS files, something that would take a while to explain.

    Suffice it to say, it CAN be done.

    Here's an image of a text element with 144pt font and an HTMLELement plugin with the font size set to 100vw (percentage of viewport width)

    The text in the HTMLElement looks like this:

    <div style = "font-size:100vw;">
    Text
    </div>

    Now, why the text element doesn't allow > 144pt, I dunno. Why it doesn't allow you to set CSS properties like the text input does? I dunno.

  • The loss of health is only one line, yes. But, you are subtracting a constant from HP_Pet, not a percentage. That means, HP_Pet is LESS in remote preview than it is in preview. So how are you setting the value of HP_Pet?

    Just curious, try this: Subtract (HP_Pet * .01) from HP_Pet

    If both preview and remote drain the same amount using the formula above then it's the value of HP_Pet that's definitely different.