Quick question — when I use sword = loadsound("sounds/sword.wav"),
joyx(), joyy(), and joybutton() don’t seem to work anymore. Any idea why?
I’m not sure — maybe I made a mistake in the code or left something out.
Would really appreciate any help — thanks a lot!
Code:
set window "The Shadow Master",400,400,false
set redraw off
07-16-2025, 12:34 PM (This post was last modified: 07-16-2025, 12:51 PM by Marcus.)
(07-16-2025, 11:47 AM)1micha.elok Wrote: Hi Marcus,
Quick question — when I use sword = loadsound("sounds/sword.wav"),
joyx(), joyy(), and joybutton() don’t seem to work anymore. Any idea why?
I’m not sure — maybe I made a mistake in the code or left something out.
Would really appreciate any help — thanks a lot!
Code:
set window "The Shadow Master",400,400,false
set redraw off
'-----------
' MAIN LOOP
'-----------
while not keydown(KEY_ESCAPE,true)
set color 0,0,0
cls
set color 255,255,255
set caret 10,10
wln "joyx : " + joyx() '1 = right, -1 = left
wln "joyy : " + joyy() '1 = bottom, -1 = up
wln
wln "button : " + joybutton(0) '1 = true, 0 = false
if joybutton(1) or keydown(KEY_SPACE,true) then play sound sword, 20
fwait 60
redraw
wend
That sounds really, really strange I'll have a look at it tonight!
Edit: I downloaded your project and tried it. Here it works as it should even when the sword sound is loaded :/ How very odd. Does the graphical window (not the console window) have focus when you use the joystick?
Edit 2: Hm, joystick and sound work here even when the window doesn't have focus. You don't have any other window open that also tries to capture joystick input? Doesn't make sense that loadsound affects it anyway ...
Well, these weird bugs are usually the nastiest. There should be absolutely no connection between joystick input and sound. If one affects the other, the cause could be memory related. That is, there may be a memory management error in the code for loading sound effects. I might be writing at invalid memory locations, causing random stuff (bugs) to appear. So I'll have to inspect the sound code and see if I find something.
Does it also happen if you use the n6 way of loading sounds?
The audio system isn't initialized until you do something music or sound related. So when you call 'loadsound', I launch the audio thread. Yesterday I thought I was on to something, because I experienced huge slowdowns every time the audio thread started. But, nah, that was just Windows Defender (that was updated yesterday) that wanted to sniff on every N7 program's butt for an hour or so.
I've looked at the code for loading audio files, and there's nothing weird in them (no memory leaks or corruption). So ... I don't know, nothing I can do about it now
But if someone else experiences something similar, please tell me!
There's one last test you could test though! What happens if you load the sound effect before calling 'set window', so that the audio thread is already running when the window is created (joystick input is window related)?
After reading the posts about joystick/sound issues, I finally found and dusted off my old Logitech joystick, to see if I could at least replicate the problem. I ran both joystick test programs via N7, with and without loading the sound, and both programs functioned just fine. All programmed buttons displayed correctly when activated... my only issue was, the first time I ran them, the stick was not detected... turned out to be poor USB contacts after a long time of no use.... Do you need an N6 test done?
07-18-2025, 07:29 AM (This post was last modified: 10-17-2025, 08:00 AM by Marcus.)
(07-18-2025, 05:51 AM)Marcus Wrote: ....
There's one last test you could test though! What happens if you load the sound effect before calling 'set window', so that the audio thread is already running when the window is created (joystick input is window related)?
@Marcus
load the sound effect before calling 'set window'....my joystick is responding well now
Thanks, Marcus, could you please tell me what happened ?
To be honest, I have no idea of why that worked. It was just a gut feeling. In the next release I'm going to try another way of capturing joystick input - the way I did it in n6. Hopefully that works better for you - and others.