Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Alarmsound does not change if changed right after deactivating it #160

Open
GHXX opened this issue Jan 4, 2021 · 4 comments
Open

Comments

@GHXX
Copy link

GHXX commented Jan 4, 2021

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:

  1. Make a new world
  2. use the /oc_sc command to plop down a opencomputers computer
  3. place an alarm block next to the computer
  4. turn on the pc
  5. open the lua prompt in oc by typing "lua" and hitting enter
    6.1. set the variable "a" to be an alarm (a = require("component").sc_alarm)
    6.2 paste in the following code snippet (as a single line! you can paste it with middle mouse button):
    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
  6. hit enter
  7. how the first sound thats installed (klaxon2) will play and keep looping, but the other will never play. (i installed 6 additional sounds, but it shouldnt matter here)
  8. now, run this snippet:
    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
image

Minecraft:

  • Mod Version (e.g. OpenSecurity-MC1.12.2-1.0-48)
  • Minecraft Version (e.g. Minecraft 1.12)
  • Forge Version (e.g. Forge 14.23.5.2854)
    (some other mods are installed, but this should not be a compatability issue i am assuming)
    image

Additional context
There are no outputs in the log file while this problem happens.

@Ocawesome101
Copy link

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 🙂

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.

@GHXX
Copy link
Author

GHXX commented Jan 4, 2021

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.

@Shuudoushi
Copy link
Contributor

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.

@CaitlynMainer
Copy link
Member

CaitlynMainer commented Jan 4, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants