roboscan's Recent Forum Activity

  • YES! That did the trick! Thank you very much!!!

    How does one get their brain to think of those alternative work-arounds? LOL

  • Would I do this by using an "if statement" (sub-event)?

    Put a for-loop inside the On Any Error as a sub-event and then in that for-loop do:

    if AJAX.tag == statusLed.ledID

    ?

  • A Clue!

    dop2000 - So I just ran it a few times looking at the console.

    When I used onError, I get this in the console:

    I confirmed these two lines are referencing my "status check" AJAX calls by disabling / enabling the call in my script. Since I am previewing, it appears that the call is actually being made to Scirra's servers (preview.construct.net/local.html) instead of my actual URL and is completing successfully as a result.

    So I changed my condition to onComplete, checked the Console again and found this!

    It would appear that even though Construct let me put the AJAX.onError inside the loop, it doesn't actually want me to do that. I believe this could certainly explain why my actions aren't firing.

    So I guess now I have to figure out another way to get it to check the result for each of my individual AJAX calls. (I will my idea of advancing a variable).

    If you or anyone has a good way of doing this, I would be greatly appreciative.

    Thank you!

  • lionz - I can share more, the rest of the code for that section is all just creating the button and some device information text from fields in the JSON file as well as changing the images used in the button based on data from the JSON file - I didn't think it was pertinent to the issue.

    dop2000 - I will look at the console log now and see if I can spot something. I know that, generally, the AJAX stuff should just be in the timeline as it fires asynchronously but I don't know how else to check for the multiple ajax calls in order to associate them with the respective "statusLed" sprites.

    The way I have this working is that I have "device category" buttons at the top of the screen. (for example "Encoders," "Processors," "Cameras"). Clicking on the category button destroys any existing elements (the link buttons and related images and text) and then creates new ones for that category (eg "Encoder 1," "Encoder 2"). When the new ones load, that is when I am trying to make the AJAX call to its URL to test if the device is online.

    So, if for example, there are 4 devices in that category (ie Encoder 1 at 10.11.12.13, Encoder 2 at 10.11.12.14 and so on), I am making 4 separate AJAX calls.

    How else could I check for errors in each of those specific AJAX calls without putting them in a loop (or hard-coding an AJAX.onError for every potential device)?

    (I suppose I could use a global "Tag variable" that advances every time an AJAX response completes or errors) so on the next loop of the script it is checking the *next* call - if that could make a difference, I certainly can try it).

    (NOTE: In the screenshot below, the AJAX request I'm using to test the status -Section 22, 5th Action- shows "" for the URL... I was just trying to force an error by using a blank URL and forgot to change it back before I took the screenshot. Normally that URL would be the variable "thisDeviceUrl" which is set at the top of line 21.)

    Here are broader screenshots:

  • I used Construct to build a "dashboard" for accessing several device GUIs for a system I maintain. In short, it loads a page of buttons on a local machine which open browser windows to the respective device URLs when clicked - all of this works great.

    I want to add an "online status" feature which changes a sprite's color for each device when the dashboard is launched (green = online, red = offline). In attempts to accomplish this, I have the program make an AJAX call to the respective devices when each button is created and will attempt to use the AJAX.onerror condition to set the status. (I realize I may have CORS issues, but that will be the next hurdle.)

    The issue I am having is getting the AJAX.onerror condition to fire. It is not firing (I've tested with oncomplete, onprogress, etc, just in case there simply was no "error" being reported). I've even tried forcing an error with a bad URL and attempting to force a complete call by calling my own server which I know will respond.

    My logic works like this:

    The dashboard buttons (links) are created from a JSON file. When the button is created, it stores a unique identifier for that button (I'm using the URL that is in the JSON file for that device) in an instance variable for the "statusLED" sprite I create which is also used as the "tag" for that buttons's status AJAX call. (This ends up looking something like "schttp://xxx.xxx.xxx", "schttp://xxx.xxx.yyy", etc.)

    Later on in the script - outside of the button-creation logic - I have a For Loop that cycles through all of the "statusLED" sprites on the page and for each of them, I am checking the AJAX onError and using that "statusLed" sprite's instance variable in the "tag" field. The idea here is that the default "statusLed" is green (sprite frame 1) and if an AJAX error occurs (no response from server device) it will set the frame to red (frame 0). I've tried "onComplete", "onanyErrors", "onanyComplete" just to see if I was simply not getting an error, but those never fire either.

    To test whether or not it is firing, I have the value of the instance variable for each "statusLED" sprite appended to a text field but it doesn't happen. When I move this "append" action outside of the onError block and just inside the For Loop, the instance variables populate the box - so I know the issue is not in the setting / recalling of the tag names.

    Any ideas what I am getting wrong here? Is the AJAX.onError not inside the ForLoop? (and if not, how else can I check multiple independent Ajax calls?)

    I have other AJAX calls to pull data in from my JSON files in other parts of the script and they are working just fine.

    (I only recently added the "statusCheck" condition as I realized this section was looping continuously - didn't help. - Also not exactly sure if the For Loop executed before the "statusCheck" var is set to 1.)

    Thank you in advance!

    Tagged:

  • So I went with time-based as per R0J0hound initial suggestion... works great!

    I'm getting the initial speed value from calculating the time from the swipe speed...

    I have a condition:

    if speed > maxWheelSpeed: speed = maxWheelSpeed

    Then I calculate a variable:

    timeTillDecel = 360 * 3 / speed

    And I timestamp when the wheel starts:

    wheelStartTime = time

    Then on every tick I am checking elapsed time:

    if time - wheelStartTime > timeTillDecel:

    If the condition is met, I keep decrementing my wheel rotation speed.

    This is working like a charm. Thank you for helping me with this!

    J

  • Another way to measure the amount the wheel rotated is to use a signed angle difference. It’s like the anglediff(a,b) expression but is negative if counter clockwise.

    angle(0,0,cos(b-a),sin(b-a))

    Will work as long as the rotation is less than 180 in a frame. You could also just use anglediff in this case I suppose since the wheel is rotating only one way.

    TotalRotation=0
    PrevAngle=0
    
    Every tick
    — add angle(0,0,cos(wheel.angle-prevAngle),sin(wheel.angle-prevAngle)) to totalRotation
    — set prevAngle to wheel.angle

    R0J0hound - I think I like your time-based idea better, but could you tell me if I am understanding what you're suggesting here...

    Are you essentially saying that I'd keep adding the changes in angle to itself and take note when the number increases a multiple of 360?

    (I don't mean to make myself sound dumb, just trying to simplify the concept).

    Thanks, again,

    J

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Can't you just give it more time by using greater than 355 degrees instead of 359, and add trigger once while true, so it does not get triggered more than once while between 355 and 360

    Sorry BadMario, I forgot to mention the "once while true" part... I don't think I realized a "once while true" condition existed. In theory that should "debounce" the repetitive counts on Every Tick, but I would still have to make the gap very large to catch the wheel position at higher speeds that it would probably affect the wheel at slower speeds. (>350 might still be too short of a gap, but >300 on a slow spin could still find a wheel that hasn't reached 360 yet when the next Tick comes around). I could probably finesse the numbers and find a close-enough spot that works for most spins, but I would feel more comfortable if I could control it more accurately.

    J

  • Can't you just give it more time by using greater than 355 degrees instead of 359, and add trigger once while true, so it does not get triggered more than once while between 355 and 360

    BadMario - Thanks for the suggestion. I actually did try this as a possible solution and also to prove to myself why my idea of using >359 wasn't working...

    I kept lowering the number (358, 355, 340, etc) just to see what would happen and I also slowed down the max speed. When the wheel is spinning very fast, it has the same issue as using 359 - the wheel is just blowing through the angles so fast that Every Tick was missing them. So as oosyrag pointed out, the wheel, even at 1 RPM just goes too fast.

    When I slowed the wheel down, the rotation count just shot up 1-2-3-4... as the wheel passed through 356,357,358, etc. because the condition "wheel.angle > 355" was being met repeatedly. This wasn't useful for my game, but it did prove to me that the "code was working," the wheel had just been moving too fast to catch it at the right position.

  • R0J0hound - Thank you for this suggestion. This could definitely work. I am already setting a max speed for the wheel. (I've been experimenting, but a max speed of 450 deg/s seems to look OK. Any faster and the wheel is just too fast that doesn't look realistic.)

    So based on this, my max speed should take about 2.4s to begin deceleration.

    Calculating the time dynamically when the wheel starts rotating and then comparing to the elapsed time on each tick should get me a good solution - I will give this a go shortly.

    Thank you for the suggestion.

    J

  • Hi,

    I've made a "Wheel of Fourtune" style interface - I have a wheel on screen you can rotate and spin by clicking/dragging or "swiping" and I programmed it to decelerate to a stop.

    However, I would like it to rotate at least 3 full rotations before it begins to decelerate and I am having trouble working this out...

    I am using the "rotate" behavior to make the wheel rotate and to count rotations, I attempted to compare the wheel angle (If more than 359, rotationCount = rotationCount + 1) in order to count the rotations on Every Tick, figuring that every time the wheel hits 360 degrees the counter would advance.

    In theory, this works (at very slow speeds). The issue is that if the wheel spins too fast (greater than 60deg/sec), the Every Tick is missing the point at which the wheel is at 360degrees and so the counter never advances (or at least advances only sporadically when the stars align). This is obviously related to the speed of "Every Tick."

    I feel like I am missing something obvious, but is there a way to run this check faster than "Every Tick" or is there a better way to count rotations that someone can suggest?

    I tried putting the wheel position comparison code outside of Every Tick, but the result is the same. I also know I have run loops before that iterate the entire loop, more or less, instantaneously so I know code can be executed faster, It seems like I am just missing something obvious here.

    Thank you for the help!

    J

  • I get it, thanks.

    Out of curiosity, C2 was a "stand-alone" program (not browser-based). Was it using the same underlying technology (was it running inside of a "white-box browser" kinda like a Phonegap app would on mobile) or was it a completely different build running stand-alone? Obviously, not relying on the browser to support the program might make the difference in what I am seeing.

    Further, we were able to preview in NW.js. Has that option gone away completely in C3? I don't see any option for that in Settings.

    Thank you,

    J

roboscan's avatar

roboscan

Member since 25 Jun, 2015

None one is following roboscan yet!

Trophy Case

  • 9-Year Club
  • Jupiter Mission Supports Gordon's mission to Jupiter
  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • Email Verified

Progress

13/44
How to earn trophies