Login
Community
DARK THEME

Timeout

How to do long calculations ?? The functions "init" and "draw" are terminated after approximately 2 seconds. Sometimes the console says "Timeout" and sometimes it doesn't. After the interruption, some data was not created correctly and the program behaves unpredictably.

A trick I use in some cases is avoiding long "for" loops and changing the loop variables inside the function "update".

Look at this code >> https://microstudio.dev/i/Loginus/performancetest/

If I call "SinArr" with several different values ​​in the "init" section, the program and the "microStudio IDE" will behave differently.

On my low end performance laptop.


sinArr = new SinArr(1) >> Run ok

SinArr START 1625591240758

SinArr Finish 1625591240794

initTime=36


Changing the value while the program is running to 10.

set sinArr = SinArr(10) >> Run ok

SinArr START 1625591246054

SinArr Finish 1625591246156

initTime=102


Each time you edit the code (even if it adds spaces), you hear a beep.

set value 100 >> Run ok

SinArr START 1625591248194

SinArr Finish 1625591248508

initTime=314


I set the value SinArr(1000) >> Can't hear the beep. I only see the text

SinArr START 1625591252256

console

sinArr

object

class = [object]

Status = "init done"

Arr = [list]

end

According to my reasoning, the program is restarted after each code edit (this was the case with each previous change of value). If there was a restart, the sinArr object should not exist. In the console I see the inscription "SinArr START" and so I know that the value of the "SinArr.Status" field should be "init start".

Changes the value of "SinArr (1)" - nothing happens. Changes the value of "SinArr (1000)" - nothing happens.

It changes the value of "SinArr(1000)" and I click "Restart project".


SinArr START 1625592449188

SinArr Finish 1625592451774

initTime=2586

Now the program works.


I set SinArr(1000000) and restart >> I am getting a warning sinArr.get is not a function.

In the console >>

sinArr

0

This is a very confusing behavior. The program may run on one computer and not on another.

When I was browsing public projects, some of them just didn't work for me (weak laptop). I figured these projects aren't finished or properly written yet.

I only had a black screen - or had to run the program several times.

Now I think that the environment in which these programs are run does not allow to verify whether a given activity was successful.

It would also be useful if you could turn off the time limit for a given activity, at least temporarily.

I can hear the sound with Firefox, but not with Google.

From Google's DevTools:

Registration succeeded. Scope ishttps://microstudio.io/Loginus/performancetest/

play.js:5991

The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu

AudioCore.AudioCore.getContext @ play.js:5991

AudioCore @ play.js:5869

Runtime @ play.js:3564

Player.Player.start @ play.js:6560

(anonymous) @ play.js:6548

XMLHttpRequest.send (async)

Player.Player.loadSource @ play.js:6555

Player @ play.js:6528

(anonymous) @ play.js:6692

load (async)

(anonymous) @ play.js:6691

play.js:6736 received: {"name":"project_file_versions","data":{"sources":{"main":{"version":374,"properties":{},"ext":"ms"},"unitsinarr":{"version":28,"properties":{},"ext":"ms"}},"sprites":{"icon":{"version":1,"properties":{"frames":1,"fps":5},"ext":"png"},"sprite":{"version":28,"properties":{"frames":5,"fps":7},"ext":"png"}},"maps":{},"sounds":{},"music":{},"assets":{}},"request_id":0}

2play.js:6736 received: {"name":"pong"}

I can suggest some trick to separate loops. Like:

init = function()
  someObject = object
    x = 0
    y = 0
  end
  objID = 0  //Processed object id
end

update = function()
  for i = 0 to 10   //Up to 10 "objects" per update
    if objID < someObjects.count then objID += 1 else objID = 0 //Check ID for existing and select a valid one every loop check
    someObj.x = [something]
    someObj.y = [something]
  end
end

In this code we do following:

  • Make loop of 10 iterations
  • Select ID that is not greater whan our limit of objects
  • Process objects with this 10 ID's
  • next update process next 10 objects
  • If you have less, than 10 objects - process some objects twice (if not needed, then you can force abort loop)

Code may be wrong in some places (just learning microscript), but you have my idea. Some time later will be making an example project.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community