How do you restart a script inside entity


#1

It seems that the script cann ot be reset. Missing button in entity properties So i cannot reload the script. and it refuse to use the new saved one. Unless you TP to other domain and back.

Need a fix for this.


#2

Yeah, we really need to be able to restart a script and/or reload script from the same URL. A “reload” button in the editor would do it: reload and restart.


#3

If you change the script value, it will reload. If you go to a different location it will reload. When I’m debugging a new local script, I often either switch domains to force or reload and/or I will use the Edit Models and the Properties dialog box to clear the script value, then set it again.

I agree that reload would make it easier. We can look at adding that. But in the meantime use one of the techniques I’ve mentioned above.


#4

I tried this, but it did not seem to work either.


#5

This problem seems still to happen. Or it’s user failure.
If i do something with deltatime and print. And delettime is not stopping because i have bug in my code i try to find with print. But i cannot update the code. it keeps runnin g the old one ?v= is failing to. only thing that works is teleport to other domain and back.

But then all windows are closed and you need to reopen and repositioning windows.


#6

Remember my insistence on selective cache invalidation. Change the field, even to the same name, and the old script goes away, a new instance (even if the same script) starts up.


#7

Yes i remember. just wanted to make a notice that i see soem problems now. this where best topic i could quick find.


#8

Maybe I’m misunderstanding but that’s already what’s happening.


#9

Reading @Richardus.Raymaker’s message I feel I should point out there is a known bug, that’ll be hard to fix without a major script engine update (on the roadmap), that causes any connection in a script entity (i.e. update, timers, mouse event, etc) to keep firing even after the entity script unload if they are not disconnected.
Changing domain will clear all that.

The best practice here is to connect your callbacks in preload and disconnect them in unload.

PS: I am not talking about entity methods that you put in the prototype, but everything under this form:

Script.update.connect(myUpdate);
Controller.mousePressEvent.connect(myMousePressEvent);
Script.setInterval(myCallback, 500);

#10

Not, i run the script from local disk, because testing. It seems you can get reload in some limbo. if you use deltatime and print command combined with failing if that need to disable the delta time. (fixt that now)

If you then disable the part in the function that use deltatime so the print is removed. It;s not stopping the print function in the log. Now im curious if interface forget to stop the existing script when you reload it , so the deltetimer keeps running ?

Unload on script inside entity. hmm. need to dig back in that corner.
Firts need to fix notepad++ , it’s not viewing the && :frowning:


#11

The script is stopped/reloaded but the callbacks are “leaked”.
This is due to the fact that all entity script share the same script engine with each a different context.


#12

Wow, thanks for pointing that out. Easy enough for now to work around it as you described.


#13

Sorry, but this part is still talking in riddles. It’s a script that get loaded from localdisk , the path is put in the entity url inside the entity.

Because i tripped again in the bug that deltatime not get stopped on reloading the script. or hwen it got changed.

Still making big progress. what 1 year ago not worked i can write now in javascript.


#14

Can I see your script?


#15

You have the script in your message box. i hope…


#16

I want option so i can set in the entities editor the option to not use cache with everything that is happening with that entity and the scripts inside.

Why, because i keep hitting my head hard against that cache wall. You think it’s reloadeed and use the changed script and then you discover you use the old one. (10 changes later). Also the print loop is annoying because script not get updated and reloaded. So i keep jumping to sandbox and back to reset it. and then i need to crawl to my entity. It’s better then 1 yerar ago, but pretty annoying still.

Mabye am misisng some logic to and the script get executed everytime and reinit. when i expect that it happens only one after reload.

Or just a simple option for my client “disable all cache”?


#17

Selective cache invalidation. Any time any property is changed/set that is reference based (URL, local disk file,etc.) is set (whether it is a change or just a set to same value), then the cache entry for that property should be invalidated. Right there right then. Also, all scene presences should be notified of that change, just as is done for any property. How hard can that be?


#18

I think something like that is mabye already working. but it takes a while sometimes before hifi noticed the file is changed on disk. It feels sometimes it ignores it complete. ?v= seems to get ignored sometimes to. possible all because soem bug C talked about before.

Mabye things would work better with the build in script editor. But i cannot work with that poor readable one. But i think you still have the same problems. file need to be saved to disk. hifi need to notice it.

Not to forget when a script reports error you are forced to try the ?v= change

Meanwhile i not always know if i do something wrong or hifi

It just happend again. Got error:
[05/13 21:47:33] [WARNING] [UncaughtException] ReferenceError: Can’t find variable: myCallback in Entities 4:16
[05/13 21:47:33] [WARNING] [Backtrace]
So i removed that line, just oops not working. updated ?v=70 (i hope not used)
Saved it, changed something no luck. now i just saved it again, and hifi notices it and theres a reload.

I get complete confused… :rolling_eyes: But now it’s working again. hard to learn javascript in hifi or fix bugs. It’s hard to debug if print screen screw things the most in deltatime.

Ghosts, the deltatime with print is having own life too. Yes ic hanged code to make soem things more easy. That’s not helping too.


#19

That’s the myth. It should not need the ?v= at all if when the URL is edited (even if the ending value is the same).Nowthere is going to be this very long discussion how there are intermediary caches, blah blah, when the communication is between interface and your asset server.


#20

Ohh, now i get it with the Script.setInterval(). , dumping deltatime.

For the other problems,
blame the user. or in the case the dev.
because am both :grin: Most seems worked out now.