0
\$\begingroup\$

Error it gives

local dontPlayMoreThanOnceDammit = false

function Behavior:Awake()
    local sound = CraftStudio.FindAsset( "motorbuson1" )
    self.mySoundInstance = sound:CreateInstance()
    self.mySoundVolume = 1.0
    self.mySoundInstance:SetLoop( true )
    self.mySoundInstance:SetVolume( 1.0 ) 
    
 end
    
function Behavior:Update()

if dontPlayMoreThanOnceDammit == false and CraftStudio.Input.WasButtonJustPressed( "on" ) then self.mySoundVolume = 1.0 self.mySoundInstance:Play()
dontPlayMoreThanOnceDammit = true
end
if CraftStudio.Input.IsButtonDown( "off" ) then self.mySoundInstance:Stop()
dontPlayMoreThanOnceDammit = false
end end
New contributor
Aloan Moreira is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
  • \$\begingroup\$ Did you mean to indent the code under the function Behavior:Update() part? \$\endgroup\$ – Vaillancourt 2 days ago
  • \$\begingroup\$ Also, describing what you're trying to do with the code helps us see the difference between your intention and what you actually ask your program to do. \$\endgroup\$ – Vaillancourt 2 days ago
  • \$\begingroup\$ Awake is preparing what to do.... and on the update, I simply say, if I press the On button, play.. and if I press the off, Stop... so but when the sounds gets played, soon the game crashes giving the error on the picture! so my guess is it is not playing the sound once even with a negating boolean, but 60 times a second.. But so how do I tel it to just play once in the update? \$\endgroup\$ – Aloan Moreira 2 days ago
  • \$\begingroup\$ I'm not fluent in Lua, but, are you missing a coma between self.mySoundVolume = 1.0 and self.mySoundInstance:Play()? \$\endgroup\$ – Vaillancourt 2 days ago
  • \$\begingroup\$ thanks! but no.. Lua, at least in this software does not require commas ;) \$\endgroup\$ – Aloan Moreira 2 days ago

Your Answer

Aloan Moreira is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.