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

script problem #10006

Closed
ripsyhehe opened this issue Aug 1, 2022 · 44 comments
Closed

script problem #10006

ripsyhehe opened this issue Aug 1, 2022 · 44 comments
Labels
help wanted Extra attention is needed

Comments

@ripsyhehe
Copy link

Describe your problem here.

made an event where u gotta spam space or else you die, but the script like breaks when it does it for the third time, like for the first time i dont spam space i take damage, second time i do spam it i take no damage, then when i dont spam again i gain health and dont die?

heres my code:

`spacePresses = 0;

function onCreate()
spacePresses = 0;
precacheImage('spacebar');
precacheSound('DODGE');
precacheSound('Dodged');
end

function onUpdate(elapsed)
if keyJustPressed('space') then
spacePresses = spacePresses + 1;
end
end

function onEvent(name, value1, value2)
if name == "DodgeEvent" then
cameraFlash('other', 'ff0000', 0.5, false)
runTimer('Mashh', 4.5);
runTimer('NOMashes', 4.5);
makeAnimatedLuaSprite('spacebar', 'spacebar', 420, 200);
luaSpriteAddAnimationByPrefix('spacebar', 'spacebar', 'spacebar', 25, true);
luaSpritePlayAnimation('spacebar', 'spacebar');
setObjectCamera('spacebar', 'other');
scaleLuaSprite('spacebar', 0.70, 0.70);
addLuaSprite('spacebar', true);
makeLuaText('mashhhhh', 'MASH SPACE!!', 1300, 10, 450)
setTextColor('mashhhhh', '990000')
setTextSize('mashhhhh', 56)
setObjectCamera('mashhhhh', 'camOther')
addLuaText('mashhhhh')
cameraShake('hud', 0.01, 4.5)
cameraShake('game', 0.01, 4.5)
cameraShake('other',0.01, 4.5)
playSound('DODGE');
end
end

function onTimerCompleted(tag, loops, loopsLeft)
if tag == 'NOMashes' and spacePresses < 10 then
removeLuaSprite('spacebar');
removeLuaText('mashhhhh');
setProperty('health', 100);
elseif tag == 'Mashh' and spacePresses > 10 then
removeLuaSprite('spacebar');
removeLuaText('mashhhhh');
setProperty('health', 100);
end
end
`

Are you modding a build from source or with Lua?

Lua

What is your build target?

Windows x64

Did you edit anything in this build? If so, mention or summarize your changes.

No response

@ripsyhehe ripsyhehe added the help wanted Extra attention is needed label Aug 1, 2022
@frantastic24
Copy link

you didn't reset the variable when the event is called
and why are you running two timers that do the same thing

@ripsyhehe
Copy link
Author

Dawg please just help me out and fix it up for me. it seems like you know what to fix lmao, im new to coding

@frantastic24
Copy link

don't ask people to do it for you

@ripsyhehe
Copy link
Author

ok fine but wdym when you said i didnt reset the variable

@frantastic24
Copy link

Set it to 0

@ripsyhehe
Copy link
Author

the timer??

@frantastic24
Copy link

no, the variable

@ripsyhehe
Copy link
Author

which variable? idk which ur talking abt

@frantastic24
Copy link

There is only one variable in the script

@ripsyhehe
Copy link
Author

what is it bro

@bruh1cat
Copy link

bruh1cat commented Aug 2, 2022

what is it bro

I think the variable is `spacePresses'

@ripsyhehe
Copy link
Author

it is 0?

@bruh1cat
Copy link

bruh1cat commented Aug 2, 2022

Idk if this made it into 1 but 'spacePresses = spacePresses + 1;'

@dezercheap10
Copy link

dezercheap10 commented Aug 2, 2022

i think they mean the 1st setProperty() in the onTimerCompleted() function

@ripsyhehe
Copy link
Author

what do i do

@dezercheap10
Copy link

change the last function to this and see if it works:

function onTimerCompleted(tag, loops, loopsLeft)
if tag == 'NOMashes' and spacePresses < 10 then
removeLuaSprite('spacebar');
removeLuaText('mashhhhh');
setProperty('health', 0);
elseif tag == 'Mashh' and spacePresses > 10 then
removeLuaSprite('spacebar');
removeLuaText('mashhhhh');
setProperty('health', 1);
end
end

@ripsyhehe
Copy link
Author

i gain health when i dont press space, why?

@ripsyhehe
Copy link
Author

the first two times it works but on the third try it does that

@dezercheap10
Copy link

try removing one of the timers then this:

function onTimerCompleted(tag, loops, loopsLeft)
if tag == 'Mashh' and spacePresses < 10 then
removeLuaSprite('spacebar');
removeLuaText('mashhhhh');
setProperty('health', 0);
elseif tag == 'Mashh' and spacePresses > 10 then
removeLuaSprite('spacebar');
removeLuaText('mashhhhh');
setProperty('health', 1);
end
end

@ripsyhehe
Copy link
Author

still does it

@dezercheap10
Copy link

may I see the current script?

@ripsyhehe
Copy link
Author

spacePresses = 0;

function onCreate()
precacheImage('spacebar');
precacheSound('DODGE');
precacheSound('Dodged');
end

function onUpdate(elapsed)
if keyJustPressed('space') then
spacePresses = spacePresses + 1;
end
end

function onEvent(name, value1, value2)
if name == "DodgeEvent" then
cameraFlash('other', 'ff0000', 0.5, false)
runTimer('Mashh', 5);
makeAnimatedLuaSprite('spacebar', 'spacebar', 420, 200);
luaSpriteAddAnimationByPrefix('spacebar', 'spacebar', 'spacebar', 25, true);
luaSpritePlayAnimation('spacebar', 'spacebar');
setObjectCamera('spacebar', 'other');
scaleLuaSprite('spacebar', 0.70, 0.70);
addLuaSprite('spacebar', true);
makeLuaText('mashhhhh', 'MASH SPACE!!', 1300, 10, 450)
setTextColor('mashhhhh', '990000')
setTextSize('mashhhhh', 56)
setObjectCamera('mashhhhh', 'camOther')
addLuaText('mashhhhh')
cameraShake('hud', 0.01, 4.5)
cameraShake('game', 0.01, 4.5)
cameraShake('other',0.01, 4.5)
playSound('DODGE');
if keyJustPressed('space') then
spacePresses = spacePresses + 1;
end
end
end

function onTimerCompleted(tag, loops, loopsLeft)
if tag == 'Mashh' and spacePresses < 10 then
removeLuaSprite('spacebar');
removeLuaText('mashhhhh');
setProperty('health', 0);
elseif tag == 'Mashh' and spacePresses > 10 then
removeLuaSprite('spacebar');
removeLuaText('mashhhhh');
end
end

@dezercheap10
Copy link

honestly idk whats wrong

@frantastic24
Copy link

you didn't reset the variable when the event is called

@ripsyhehe
Copy link
Author

HOW do i reset it? do i move the variable under on event?

@frantastic24
Copy link

Set it to 0

@ripsyhehe
Copy link
Author

then theres no point to the event?
it wont do anything?

@frantastic24
Copy link

No, as the event is now it has no point because you can mash space at the start of the song and completely ignore the event
That is why you reset the variable to 0

@ripsyhehe
Copy link
Author

its already 0....?

@frantastic24
Copy link

spacePresses = spacePresses + 1;

Are you just ignoring this line

@ripsyhehe
Copy link
Author

yeah because if i change it to 0 the event wont do anything

@ripsyhehe
Copy link
Author

i just fixed it

@ripsyhehe
Copy link
Author

nvm it still doesnt work

@frantastic24
Copy link

yeah because if i change it to 0 the event wont do anything

I didn't tell you to change it 💀 that line is the reason you need to reset the value

@ripsyhehe
Copy link
Author

dawg, then how do i reset it, ive been on this shi for days what do i change bruv

@frantastic24
Copy link

I've already told you twice

@ripsyhehe
Copy link
Author

spacePresses = spacePresses + 0; ????

@frantastic24
Copy link

That's adding 0, it does nothing

@ripsyhehe
Copy link
Author

its not spacePresses = spacePresses + 1; or spacePresses = 0; so what is it

@DabbinDude316B
Copy link

HeY tHaT’s My cOdE

@ripsyhehe
Copy link
Author

yea thanks

@DabbinDude316B
Copy link

spacePresses = 0;
pressesCount = false;

function onCreate()
     precacheImage('spacebar');
     precacheSound('DODGE');
     precacheSound('Dodged');
end

function onUpdate(elapsed)
     if keyJustPressed('space') and pressesConut then
          spacePresses = spacePresses + 1;
     end
end

function onEvent(name, value1, value2)
     if name == "DodgeEvent" then
          cameraFlash('other', 'ff0000', 0.5, false)
          runTimer('Mashh', 5);
          makeAnimatedLuaSprite('spacebar', 'spacebar', 420, 200);
          addAnimationByPrefix('spacebar', 'spacebar', 'spacebar', 25, true); 
          playAnimation('spacebar', 'spacebar');
          setObjectCamera('spacebar', 'other');
          scaleObject('spacebar', 0.70, 0.70);
          addLuaSprite('spacebar', true);
          makeLuaText('mashhhhh', 'MASH SPACE!!', 1300, 10, 450)
          setTextColor('mashhhhh', '990000')
          setTextSize('mashhhhh', 56)
          setObjectCamera('mashhhhh', 'camOther')
          addLuaText('mashhhhh')
          cameraShake('hud', 0.01, 4.5)
          cameraShake('game', 0.01, 4.5)
          cameraShake('other',0.01, 4.5)
          playSound('DODGE');
          pressesCount = true;
     end
end

function onTimerCompleted(tag, loops, loopsLeft)
     if tag == 'Mashh' and spacePresses < 10 then
          removeLuaSprite('spacebar');
          removeLuaText('mashhhhh');
          setProperty('health', 0);
     elseif tag == 'Mashh' and spacePresses > 10 then
          removeLuaSprite('spacebar');
          removeLuaText('mashhhhh');
     end
end

Try this.

@ripsyhehe
Copy link
Author

ripsyhehe commented Aug 2, 2022

doesnt work
also i updated the code
and i know its completely messy idk how else to fix it:

spacePresses = 0;
pressesCount = false;

function onUpdate(elapsed)
if keyJustPressed('space') and pressesConut then
spacePresses = spacePresses + 1;
end
end

function onEvent(name, value1, value2)
if name == "DodgeEvent" then
removeLuaText('ten')
removeLuaText('nine')
removeLuaText('eight')
removeLuaText('seven')
removeLuaText('six')
removeLuaText('five')
removeLuaText('four')
removeLuaText('three')
removeLuaText('two')
removeLuaText('one')
removeLuaText('zero')
cameraFlash('other', 'ff0000', 0.5, false)
runTimer('Mashh', 4.5);
runTimer('byebye', 4.5);
runTimer('10', 0.01);
runTimer('9', 0.01);
runTimer('8', 0.01);
runTimer('7', 0.01);
runTimer('6', 0.01);
runTimer('5', 0.01);
runTimer('4', 0.01);
runTimer('3', 0.01);
runTimer('2', 0.01);
runTimer('1', 0.01);
makeAnimatedLuaSprite('spacebar', 'spacebar', 420, 200);
luaSpriteAddAnimationByPrefix('spacebar', 'spacebar', 'spacebar', 25, true);
luaSpritePlayAnimation('spacebar', 'spacebar');
setObjectCamera('spacebar', 'other');
scaleLuaSprite('spacebar', 0.70, 0.70);
addLuaSprite('spacebar', true);
makeLuaText('mashhhhh', 'MASH SPACE!!!', 1300, 10, 450)
setTextColor('mashhhhh', '990000')
setTextSize('mashhhhh', 56)
setObjectCamera('mashhhhh', 'camOther')
addLuaText('mashhhhh')
cameraShake('hud', 0.01, 4.5)
cameraShake('game', 0.01, 4.5)
cameraShake('other',0.01, 4.5)
playSound('DODGE');
pressesCount = true;
end

function onTimerCompleted(tag, loops, loopsLeft)
if tag == 'Mashh' and spacePresses < 10 then
setProperty('health', 0);
elseif tag == 'Mashh' and spacePresses >=10 then
doNothing()
elseif tag == '10' and spacePresses >= 0 then --ten
makeLuaText('ten', ' 10', 1300, 10, 450)
addLuaText('ten')
elseif tag == '10' and spacePresses >= 1 then --ten
removeLuaText('ten')
elseif tag == '9' and spacePresses >= 1 then
makeLuaText('nine', ' 9', 1300, 10, 450)
addLuaText('nine')
elseif tag == '9' and spacePresses >= 2 then
removeLuaText('nine')
elseif tag == '8' and spacePresses >= 2 then
makeLuaText('eight', ' 8', 1300, 10, 450)
addLuaText('eight')
elseif tag == '8' and spacePresses >= 3 then
removeLuaText('eight')
elseif tag == '7' and spacePresses >= 3 then
makeLuaText('seven', ' 7', 1300, 10, 450)
addLuaText('seven')
elseif tag == '7' and spacePresses >= 4 then
removeLuaText('seven')
elseif tag == '6' and spacePresses >= 4 then
makeLuaText('six', ' 6', 1300, 10, 450)
addLuaText('six')
elseif tag == '6' and spacePresses >= 5 then
removeLuaText('six')
elseif tag == '5' and spacePresses >= 5 then
makeLuaText('five', ' 5', 1300, 10, 450)
addLuaText('five')
elseif tag == '5' and spacePresses >= 6 then
removeLuaText('five')
elseif tag == '4' and spacePresses >= 6 then
makeLuaText('four', ' 4', 1300, 10, 450)
addLuaText('four')
elseif tag == '4' and spacePresses >= 7 then
removeLuaText('four')
elseif tag == '3' and spacePresses >= 7 then
makeLuaText('three', ' 3', 1300, 10, 450)
addLuaText('three')
elseif tag == '3' and spacePresses >= 8 then
removeLuaText('three')
elseif tag == '2' and spacePresses >= 8 then
makeLuaText('two', ' 2', 1300, 10, 450)
addLuaText('two')
elseif tag == '2' and spacePresses >= 9 then
removeLuaText('two')
elseif tag == '1' and spacePresses >= 9 then
makeLuaText('one', ' 1', 1300, 10, 450)
addLuaText('one')
elseif tag == '1' and spacePresses >= 10 then
removeLuaText('one')
elseif tag == 'byebye' then
cameraFlash('other', '000000', 0.5, false)
removeLuaSprite('spacebar');
removeLuaText('mashhhhh')
end
end
end

@ripsyhehe
Copy link
Author

plz help me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants