Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[HELP] joystick vs loadsound
#1
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

'sound effect
sword           = loadsound("sounds/sword.wav")

'-----------
' 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


Attached Files
.zip   testjoy.zip (Size: 35.49 KB / Downloads: 3)
Reply
#2
(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

'sound effect
sword           = loadsound("sounds/sword.wav")

'-----------
' 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 Smile  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 ...
Reply
#3
Don't worry Marcus... I think the problem is on my old gamepad that needs to be replaced with a new one  Big Grin Big Grin Big Grin
Reply
#4
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?

Code:
sword = 1
load sound sword, "sounds/sword.wav"
Reply
#5
(07-17-2025, 06:12 AM)Marcus Wrote: ...
Does it also happen if you use the n6 way of loading sounds?

Code:
sword = 1
load sound sword, "sounds/sword.wav"

unfortunately, my joystiick still doesn't like "load sound"  Big Grin
Reply
#6
Good news !!!  Big Grin
Though my joystick doesn't like loadsound, it likes loadimage 

Code:
#win32
set window "The Shadow Master",200,200,false,2
set redraw off

'load image
sprite = loadimage("img/player.png",4,1)

'-----------
' 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) then draw image sprite,100,100,1
   
    fwait 60
    redraw
wend


Attached Files
.zip   testjoy2.zip (Size: 1.15 KB / Downloads: 2)
Reply
#7
I can't explain the behavior. It's super weird.

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 Sad

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)?
Reply
#8
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?
Logic is the beginning of wisdom.
Reply
#9
(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 ? 

@Johnno, thanks for your feedback, too.
Reply
#10
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)