Wiremod Expression 2

Maybe someone can enlighten me as to why this code works fine


@name Rave Break
@inputs Num Em1:entity Em2:entity Em3:entity Em4:entity P1:entity
@outputs Go

if (Num == 1){
    Em1:soundPlay(1,0,"custom/RAVEBREAK.mp3")
    Em2:soundPlay(2,0,"custom/RAVEBREAK.mp3")
    Em3:soundPlay(3,0,"custom/RAVEBREAK.mp3")
    Em4:soundPlay(4,0,"custom/RAVEBREAK.mp3")
    Go = 1
}
else{
    soundPurge()
    Go = 0
}

but this code keeps starting the song over and over again as soon as R == 254. Basically it stutters and then i hear nothing.


@name CD Player Play
@inputs R Sp1:entity Sp2:entity
@outputs Go


if (R == 254){
    Go = 1
    Sp1:soundPlay(1,0,"custom/broll.mp3")  
}
else{
    Go = 0
    soundPurge()
}

EDIT: So i restarted my game and replaced the chip and other things and got it to work but i now want to add other colors in but i’m not sure how i would add the other lines I don’t think this is correct but if you could give suggestions


@name CD Player Play
@inputs R G Sp1:entity Sp2:entity
@outputs Go


if (R == 254){
    Go = 1
    Sp1:soundPlay(1,0,"custom/broll.mp3")  
}
else{
    Go = 0
    soundPurge()
}
if (G == 254){
    Go = 1
    Sp1:soundPlay(1,0,"custom/ravebreak.mp3")  
}
else{
soundPurge()
}

The problem with the second E2 you posted was that, as soon as R hit 254, the code that told the E2 to play the sound would execute over and over again, because the condition would remain true.
That’s the thing with Expression 2, as long as a condition remains true, a code block will continue to execute.

Replacing


R == 254

with


R == 254 & ~R

would solve that problem because now you’re telling the E2 “If ‘R’ equals 254 and the variable ‘R’ has changed just recently, then execute this block of code below me”.
[release]
TIP: “~Variable” only works for inputs. For persist variables, you’d replace “~” with “$”, or use changed(*)
[/release]



@name CD Player Play
@inputs R G B Sp1:entity Sp2:entity
@outputs Go


if (R == 255 & ~R){
    Go = 1
    Sp1:soundPlay(1,0,"custom/broll.mp3")  
}
elseif (G == 255 & ~G){
    Go = 1
    Sp1:soundPlay(2,0,"custom/ravebreak.mp3")  
}
elseif (B == 255 & ~B){
    Go = 1
    Sp1:soundPlay(3,0,"LOLSOUND.mp3")  
}
else{
    Go = 0
    soundPurge()
}


Also, colors go up to 255, not 254. I’ve integrated that into a new E2, above, which also supports B (Or “Blue”, from what I gather).

Thanks alot.