gibbon's Forum Posts

  • There appears to be a lot of effort gone in to enable loading images into sprites from urls, base64, binary object, local storage etc.

    But why is there no easy way to simply save the loaded image as a base64, or save it into binary etc?

    Do we really have to do the whole complex "snapshot" the canvas (LayerToCanvas, DevicePixelRatio ETC) then request that using ajax, into binary and convert to base64...

    I have loaded an image from a URL (API), all i want to do is simply save that loaded image "somewhere" either into local storage or post it somewhere as base64.

    EDIT / UPDATE

    The way I am having to dnow do this is:

    - Ajax request the image straight into binary.

    - Then load the image from baniary into the sprite.

    - Can now send / save the binary/base64 as i wanted.

    I still wish there was a way to simply, "Get image from sprite".

    Andy

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I have finally figured this out so posting the answer for future users (including myself!). From my initial test this will snapshot the area of "Sprite2" regardless of screen size ETC.

    I still this there could easily be another function added to the likes of "Take snapshot of area" and it does all this for you?

  • Hi, I am trying to take a canvas snapshot (not drawing canvas) of a particular area (in this case a sprite (Sprite2)) and I cannot work out why its not working using the events as shown in the photo. To be honest, I've been down this road before and gave up, apparently it is possible, why it has to be made so difficult I'm not sure.

    The following works only if the window/browser/viewport is exactly the right size to the layout. Otherwise, it appears the Offset works (X,Y) but the Width and Height are still incorrect.

  • It's difficult to tell exactly what is happening, but since you said you are using some javascript, is it possible that some of those snippets are using the await keyword?

    If that is the case, the javascript is asynchronous and needs to be waited for before continuing if you want to keep things running sequentially.

    https://www.construct.net/en/make-games/manuals/construct-3/scripting/using-scripting/scripts-in-event-sheets

    Just realised that it does thrown and error in the console when trying to load files without the "wait for previous action to complete" in place.

    Uncaught (in promise) RangeError: Maximum call stack size exceeded - in Parameter.js

    Why is this?

    EDIT

    I have changed this so now it doesn't run the function from within the function, but instead it runs it separately every tick. I then realised it was fixed at 60 fps (v-synced) so will only read lines at 60/s, changed it to unlimited and it now reads them as fast as it can, and successfully.

  • I understand, I apologize, I am somewhat desperate, in the forums that I have entered most of the people are inactive, I thought I could find help in the forums where they have been sharing them for a short time, again I apologize and withdraw.

    That's fine, but your just plucking at straws and hoping for the best whilst clogging forum posts up with repetitive content.

    Post your own thread, with a relative title and someone who sees it will help. Trust me you will be much more likely to get a response that way rather than try at other users posts that are trying to resolve their own issues.

  • sorry, what happens is that the behavior I had in construction2 now that I am going to export to contruc3 tells me that I must have installed the ZIGZAG behavior made by rex.rainbow, the problem is that I can't find that behavior for contruc3, so it won't let me opening the project, I've looked for it everywhere and I can't find it, and removing it from the game would open new bugs.

    You might want to open your own forum post as apposed to just jumping on other random ones?

    My original post has no link to what your asking for.

  • Hi brother! don't you happen to have the ZIGZAG behavior for construct3? or any tutorial to pass that behavior to c3 file?

    ?? Sorry, not a clue what your on about?

  • I have done a bit more digging and found that the data may actually be correct, I was receiving some odd numbers but found the other systems I was using to check/validate actually had filters that would omit data it deemed as inaccurate.

    So I have put in similar filters and now getting better results.

    However, I still cant work out the final issue of why I cant run the function loop as fast as possibly allowed in order to read the lines of data, but instead HAVE to have:

    "wait for previous action to complete" before reading the next line for it to work and load all the lines without breaking?

    Thanks

  • It's difficult to tell exactly what is happening, but since you said you are using some javascript, is it possible that some of those snippets are using the await keyword?

    If that is the case, the javascript is asynchronous and needs to be waited for before continuing if you want to keep things running sequentially.

    https://www.construct.net/en/make-games/manuals/construct-3/scripting/using-scripting/scripts-in-event-sheets

    I have double and triple checked and all the JS I have written certainly doesn't and the 1 JS library that I'm using also doesnt appear to be doing.

    I will see if I can do a stripped back version of the issue and upload/send it over to you guys over to have a look. I cant quite fathom whats causing the issue despite doing some deep data analysis comparing the outcome of the line reads in C3 to other systems, very odd.

    As a test I changed the "wait for previous action to complete" to a wait for 0.5 seconds (between each line read) and loaded a file, but got the same results? Surely that would have given enough time to do everything, there only simple calcs and storing numbers in global arrays.

    What I don't get is why If I remove the "wait for previous action to complete" I cant fully load a file that has over 500 lines in? Its never the same line either, it just breaks at anything between 400 - 1000.

  • I am trying to figure out why I am getting some odd results and I'm sure its a lack of understanding with what's going on at certain points so I was wondering if someone could maybe explain the following which Im sure will lead me in the right direction.

    To help undertsand: I am loading a text file which contains lines of data, some have 500/600 lines and some might have 3000+ lines. What I ORIGINALLY did was create a loop to go through each line, read it, token it up, process some of the data (run the lines data though some calcs and functions) and then display it in a nice way at the end. The issue with this though was the "hang time" caused from all of the above happening in one tick.

    To solve this I did the following (which maybe the start of the issue)

    I crated a function with a line index parameter, which did all the reading and processing of a line at n index. At the end of the function I would simply call the function again with the next line index, until at the last line. This "function loop" works with some of the SMALLER files (upto around 500 lines) but what I found was anything over that and the function loop seemed to break... So I tried putting a "wait for previous action to complete" just before I call the function again with the next line index. Whilst this slowed the whole read process down, it seemed to work, read all lines just fine and does not hang the project. However, it is the start of some strange results from the data.

    In each function call, I grab the line of data (just comma delimited numbers and string's) (and sometimes the previous line) and I run them through various EVENT functions AND some JavaScript functions. But I'm finding some data to not be quite right, and its almost like its processing some lines at the wrong time in the function call, but they all use the same index var as the line ref.

    Here is a photo which shows the function loop I describe above.

    So is this because some of the functions I am calling are not finishing before it gets called again? Is there anything I need to do to these functions (both event funcs and JS funcs) to make sure they finish before continuing? The Event functions are NOT set to async nor are the JS functions.

    What I find strange is, nothing inside the function call actually has the little "wait" symbol (indicating a wait is required), yet putting the "wait for previous action to complete" before calling the function again does slow the loop down and loads all the lines, as apposed to if its not there only smaller files get loaded and big ones seem to break half way through reading the lines (500+)

    Thanks.

  • HI, i Have an issue with the scrollview and the new HTML element as part of the latest Beta.

    When you have the HTML element as a child to the scrollview content and then "scroll up" the HTML Element stops when it gets to the top of the viewport?

    Thanks

  • Thanks, and please don't think I'm being negative or not trying. But as noted in my original post, I have unfortunately already tried this.

    Thanks

    Andy

  • It depends on the specific library. Until fairly recently there wasn't a language-standard way to access the global object or use modules in JavaScript. Construct is based on the modern approach of using JS Modules and globalThis for global access. Modern scripts that are based on modules should work fine. But older scripts may need tweaking to work.

    For example if an old script tries to declare a global variable with var myGlobal = ..., that will need changing to globalThis.myGlobal = .... Also if the script doesn't actually export anything, you won't be able to use it with an imported name - you'll have to rely on global variables.

    Thanks Ashley, I have given up on trying to get the Chartish JS library to work which is very disappointing, its not a old library and in fact quite modern and highly used but I cannot fathom why it gives the "global not defined error"...

  • To continue on from this, im still very confused...

    Im not sure if is because I come from a HTML, JS and PHP dev background where you can just include and call any JS library with ease, but why this isn't the same in C3 is very frustrating and disappointing.

    With C3 now having the vanilla HTML Element, and the already JS capabilities I feel we C3 is missing a trick in not being able to use the thousands of JS libraries already out there...

    For instance..

    I am trying to add Chartish JS library (a light weight single file charting library), just a JS file and CSS, in standard HTML works a treat.

    Add the files to C3 project, import the JS file inside "importForEvents" and I get a error on preview and the console states the following:

    	Uncaught ReferenceError: global is not defined
     at chartist.min.js:8:9794
     at chartist.min.js:8:180
     at chartist.min.js:8:184
    domSide.js:25 [C3 runtime] Failed to load JavaScript code used in events. Check all your JavaScript code has valid syntax.
    

    What has to be done to get this working? I have tried changing all ref of global inside the JS file to globalThis but no luck.

    If we could easily include all the readily available JS libraries the scope for lovely looking interfaces ETC is huge.

    Worker is also Off

  • I have managed to (and very easily) add openlayers.js to my project and get it working nicly with the new HTML element.

    I did this simply by importing the ol.js and ol.css files, putting the JS file in scripts and I set its purpose as "importforevents". Then I found that in my events I can initialise the map and make changes to it ETC. Great!

    My next step was to add another script for "charts", so I did the same but realised that when I set the chart JS file to importForEvents it removes this purpose from the OL.js.

    So did some reading up and read I need to import these JS script into main and into a seperate "importForEvents.js" file to make them available inside events.

    So to keep things simply I thought I would attempt this with JUST the ol.js but I am having no luck whatsoever.

    Current "non working" situation is:

    Main.js (purpose set to main)

    	import * as myMaps from "./ol.js";
    

    importForEvents.js (Purpose set to importForEvents)

    	import * as myMaps from "./ol.js";
    

    When I try to initiialise the map from within an event script using the following

    	var map = new myMaps.ol.Map({
     target: 'map',
     layers: [
     new ol.layer.Tile({
     source: new ol.source.OSM()
     })
     ],
     view: new ol.View({
     center: ol.proj.fromLonLat([37.41, 8.82]),
     zoom: 4
     })
     });
    

    I get the following colse error:

    Unhandled exception running script Event sheet 1, event 17, action 2: TypeError: Cannot read properties of undefined (reading 'Map')

    If I remove the "myMaps." from "var map = new myMaps.ol.Map" in the above code then it works, but surely that is then not referring to the imported script?