Open GHXX opened 3 years ago
DISCLAIMER: I could be way off here, this an educated guess based on general knowledge of OpenComputers and Minecraft, having largely never looked at the source code of either. I'm not interested in arguing about this; this is just my $0.02 :slightly_smiling_face:
Because of how OpenComputers works, and because Minecraft is limited to 20 ticks per second, and because of concurrency issues (ever gotten a ConcurrentModificationException
?) or something like that, certain external (usually world-affecting) values (for example, when you update a redstone wire) updated by the Lua state can only be changed when said Lua state yields, e.g. when os.sleep
is called.
Basically, you're not giving the sound time to update.
Yeah, its fairly safe to say that its not updating quickly enough. No exceptions thrown while testing, but there is definitely some synchronization work to be done on opensecurity in my opinon. Or a cheap waittime.
Yeah, its fairly safe to say that its not updating quickly enough. No exceptions thrown while testing, but there is definitely some synchronization work to be done on opensecurity in my opinon. Or a cheap waittime.
Um... I don't think you understand what was said... This is most likely a tick rate, or timing, issue. It's not really something that can be fixed by the mod dev. Opencomputers itself has hard baked timing limits to prevent people from crippling servers, last I checked it was something like 2 ticks or so.
You've found the one and only fix here. Sleep for a bit after changing the sound. 0.01 is enough to make this work.
for i=1,#a.listSounds() do al = a.listSounds()[i]:gsub(".ogg",""); print(al);a.setAlarm((al)); os.sleep(0.01); a.activate(); os.sleep(5);a.deactivate() end
Is enough to fix this.
This is 100% a delay in how long it takes OpenComputers to push this change to the TE, and for MC to Sync the TE from the server to the client. ALL OC operations happen on the server TE, and all sound operations happen on the Client TE.
https://github.com/PC-Logix/OpenSecurity/blob/1.12.2/src/main/java/pcl/opensecurity/common/tileentity/TileEntityAlarm.java#L41-L56 which calls https://github.com/PC-Logix/OpenSecurity/blob/1.12.2/src/main/java/pcl/opensecurity/common/tileentity/TileEntityOSSound.java#L86-L89
Describe the bug When calling the .setAlarm() lua function of the alarm block right after calling .deactivate(), and activating it immediately after, then it does not change.
In which environment did the Bug appear? Singleplayer, fresh world.
To Reproduce Steps to reproduce the behavior:
for i=1,#a.listSounds() do al = a.listSounds()[i]:gsub(".ogg",""); print(al);a.setAlarm((al)); a.activate(); os.sleep(5);a.deactivate() end
for i=1,#a.listSounds() do al = a.listSounds()[i]:gsub(".ogg",""); print(al);a.setAlarm((al)); a.activate(); os.sleep(5);a.deactivate();os.sleep(0.5) end
and now it will work properly.Expected behavior The sound should change when deactivating the alarm, changing it an reactivating it. Adding an extra "os.sleep" should not be necessary under any circumstances.
Screenshots / Code Snippet
Minecraft:
Additional context There are no outputs in the log file while this problem happens.