roboscan's Forum Posts

  • 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

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

  • Hi Ashley, thanks for your reply.

    Yesterday, I tried running C3 in Edge and in Firefox. More or less, the result was the same.

    Wondering if the issue is related to some other actions I have going on in my project, I deleted my elements, layers, and actions one by one until I saw an improvement. I never did. I even tried adding some "on playback events" (stuck, error, not ready to play) to reveal some text showing when an error occurred, but no response - the preview would just crash.

    I got down to just a single layer with one video element and had it play the video on start. I then previewed multiple times. Sometimes the video played just fine.. sometimes the video was choppy but didn't crash. Sometimes it would be choppy and crash almost immediately. Sometimes it would just crash a half second after starting before it would play at all.

    Again, when I upload to my webserver, the game and video play (mostly) ok. (If my network connection is crappy, I have seen some video errors) but that is it.

    Lastly, I started building this game in C2 and only finally upgraded to C3 two weeks ago because of the improved JSON functionality (thanks, btw!). I was not having these preview issues in C2 with the same video files.

    It's not the end of the world, but obviously being able to preview successfully / repeatedly is a huge help. I was more or less hoping this might be a known thing with some kind of fix.

    (...and I realize it could be something wonky with my video files, but I've edited the video file a few times but the issue stays...)

    Thank you, again,

    J

  • Don't see how I can edit a post - I wanted to add that I am using Construct 3 in Chrome in Windows 10.

  • Hi,

    I am making a game of sorts as a joke for my co-workers. The game starts up, plays an intro screen - when you click to start, it plays a video. Every 10 seconds (time gets shorter as time goes on) a dialog pops up asking a question which they have to answer.

    When I publish this on my webserver, it is running pretty well, however when I try to preview while editing in Construct 3, the preview windows crashes shortly after the video starts playing with "STATUS_ACCESS_VIOLATION" in the browser window.

    It does not always crash at the same spot and it does not always crash. (is "crash" even appropriate here?.) But more times than not, it keeps happening.

    When I try to preview with Debug on, it will display the Debug screen, but when the video starts, the screen just freezes and I can only hear the audio. You can't interact with the game. I don't see anything out of the ordinary with respect to processor or memory.

    I have the video in both Mp4 (about 70mb) and WEBM (about 15mb) available to the game. I have tried removing either file to see if it is an issue with one format or the other, but the problem seems to happen with either.

    I almost get the feeling like the video is not loading fast-enough for playback, but I am using a pretty powerful PC and have my files on an SSD - I wouldn't think file access speed would be an issue, especially compared to streaming from a webserver, where I am NOT having these issues.

    Does anyone have any suggestions of what I can look for as possible causes?

    Thank you!

  • Hi, Went with dictionary. Worked like a charm. Simplified my unique-randomizer function, too. Thank you very much for the help and suggestion!

    J

  • I think I am going to go with a Dictionary - seems like a simpler concept for what I'm trying to do. In essence what I am creating is like a "trivia game." My goal is to simply randomize the questions ("issues" in my case) without repeating the questions.

    If I am understanding, what I am going to do is create a "issueLog" dictionary of keys with no values and just store my "already used numbers" (the "issue" indexes) as the Keys of each new dictionary entry. Then I will use the Has Key condition for the dictionary to determine if that index has already been added to the dictionary and perform the correction actions based upon that result.

    Gonna work on this now - thanks again for the advice!

  • Hi, thanks for your help... do you mean use a dictionary to store my “issueLog” instead of using an array? Just for clarification as I have done a lot with C2 but haven’t used dictionaries that much, the “if exists” functionality that you’re referring to is a dictionary-specific function as an alternative to my looping over the array and attempting to compare each value? That definitely sounds like a cleaner way to do things. I will look at that later.

    Thank you very much!

    J