OpenMods / OpenPeripheral-Addons

An addon for OpenPeripheral, adding physical blocks and items to the game
MIT License
11 stars 10 forks source link

glass.clear() is terminating Connection #43

Closed Holladiewal closed 9 years ago

Holladiewal commented 9 years ago

when I use this program: http://pastebin.com/PA92J9PH it terminates the Connection after a few Seconds, when I wear the glasses.

The Errormessage from the console/log:http://pastebin.com/7YPmFzuB

Hope you can help me

boq commented 9 years ago

Part or problem was your code, recreating objects every tick instead of updating fields, like this:

label = p.addText(10, 10, `Hello`)
label.setText('World')

Object creation is very "heavy" operation, changing single attribute (text, color, position) - not.

Other part of problem was race condition in our code. I fixed it, but now every change has to be manually send to players with .sync() command. This function is limited to one call per tick - don't use it very often in loop.

Holladiewal commented 9 years ago

So I won't be able to run my program without a sleep(0.5) anymore or it is possible to keep up the live notification system without that sleep?

boq commented 9 years ago

No. As I said, updates are no longer send automatically, you need to call .sync() on peripheral - and this command is automatically limiting update rate to one per tick (execution of program will momentarily pause). No extra limiting needed.

Holladiewal commented 9 years ago

So I can just keep spamming .sync()?

boq commented 9 years ago

They aren't cheap (one call - one net packet), so no. Once per loop should be enough. One after every addSomething - total waste of bandwidth.

Holladiewal commented 9 years ago

That was what I meant with spamming. Once per loop without a sleep.

Holladiewal commented 9 years ago

Tried updating fields in latest verson from jenkins and as soon as i call

l = glass.setText(1,255,"Morning") l.setText("TEST")

i get the error

lua:1:attempt to call nil

what am i doing wrong?

boq commented 9 years ago

For some time OpenPeripheralCore returned strings instead of objects. Please update that too.

Holladiewal commented 9 years ago

thanks, now it is working