Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do I make repeat until blocks and variables work in custom blocks?
- Koamodo975
-
Scratcher
1000+ posts
How do I make repeat until blocks and variables work in custom blocks?
So I'm STILL having troubles with my Fresh Platformer Engine (a scrolling non-tile platformer engine similar to MEEK: DEMO), which I've made a topic about already. But now, I just got a thought: All my problems would probably be solved if I knew how to get variables to work with custom blocks. When I tried to use the repeat until block for my wall detection:
define wall detectBut as soon as the player touches the ground, the game freezes for a second, then the character is instantaneously shot into the air, changing the y var by a TON. Is there any workaround for this?
set [slope v] to [0]
set [old x v] to (player x)
repeat until <<not <touching [ground v] ?>> or <(slope)= [8]>>
change [player y v] by (1)
change [slope v] by (1)
end
if <touching [ground v] ?> then
change [ player y v] by ((0) - (slope))
set [player y v] to (old x)
end
- yadayadayadagoodbye
-
Scratcher
1000+ posts
How do I make repeat until blocks and variables work in custom blocks?
Yes, loops do not work in custom blocks which do not have screen refresh, as without screen refresh, the custom block would continue functioning until the next frame, thus, rather then bumping the player up by as much as you need so it doesn't touch the ground, it instead increases the player's supposed y position, but not the actual, leading to the player shooting up in the next frame.
Instead, just use a load of nested if statements, something like
Instead, just use a load of nested if statements, something like
if <not <<touching [ground v] ?> or <(slope) = [8]>>> then
change [y v] by (1)
change [slope v] by (1)
if <not <<touching [ground v] ?> or <(slope) = [8]>>> then
change [y v] by (1)
change [slope v] by (1)
if <not <<touching [ground v] ?> or <(slope) = [8]>>> then
change [y v] by (1)
change [slope v] by (1)
if <not <<touching [ground v] ?> or <(slope) = [8]>>> then
change [y v] by (1)
change [slope v] by (1)
if <not <<touching [ground v] ?> or <(slope) = [8]>>> then
change [y v] by (1)
change [slope v] by (1)
end
end
end
end
end
Last edited by yadayadayadagoodbye (Feb. 21, 2024 19:54:50)
- evantparkes
-
Scratcher
100+ posts
How do I make repeat until blocks and variables work in custom blocks?
It looks like as the player falls, it will change slope and player y by one. It will bounce the player up by slope(the number of times the script repeats. Try changing it by a smaller amount.
So I'm STILL having troubles with my Fresh Platformer Engine (a scrolling non-tile platformer engine similar to MEEK: DEMO), which I've made a topic about already. But now, I just got a thought: All my problems would probably be solved if I knew how to get variables to work with custom blocks. When I tried to use the repeat until block for my wall detection:)define wall detectBut as soon as the player touches the ground, the game freezes for a second, then the character is instantaneously shot into the air, changing the y var by a TON. Is there any workaround for this?
set [slope v] to [0]
set [old x v] to (player x)
repeat until <<not <touching [ground v] ?>> or <(slope)= [8]>>
change [player y v] by (1)
change [slope v] by (1)
end
if <touching [ground v] ?> then
change [ player y v] by ((0) - (slope))
set [player y v] to (old x)
end
- Koamodo975
-
Scratcher
1000+ posts
How do I make repeat until blocks and variables work in custom blocks?
Yes, loops do not work in custom blocks which do not have screen refresh, as without screen refresh, the custom block would continue functioning until the next frame, thus, rather then bumping the player up by as much as you need so it doesn't touch the ground, it instead increases the player's supposed y position, but not the actual, leading to the player shooting up in the next frame.OH that's why all those other games did that. I'ma try it.
Instead, just use a load of nested if statements, something likeif <not <<touching [ground v] ?> or <(slope) = [8]>>> then
change [y v] by (1)
change [slope v] by (1)
if <not <<touching [ground v] ?> or <(slope) = [8]>>> then
change [y v] by (1)
change [slope v] by (1)
if <not <<touching [ground v] ?> or <(slope) = [8]>>> then
change [y v] by (1)
change [slope v] by (1)
if <not <<touching [ground v] ?> or <(slope) = [8]>>> then
change [y v] by (1)
change [slope v] by (1)
if <not <<touching [ground v] ?> or <(slope) = [8]>>> then
change [y v] by (1)
change [slope v] by (1)
end
end
end
end
end
- Koamodo975
-
Scratcher
1000+ posts
How do I make repeat until blocks and variables work in custom blocks?
It's kinda working? Now the character can still walk through walls tho.~snap snap~ le crabOH that's why all those other games did that. I'ma try it.
- Malicondi
-
Scratcher
1000+ posts
How do I make repeat until blocks and variables work in custom blocks?
Yes, loops do not work in custom blocks which do not have screen refreshloops very much do work in custom blocks with or without run without screen refresh. If you need it to happen in 1 frame (instantly) then it will need run without screen refresh.
- yadayadayadagoodbye
-
Scratcher
1000+ posts
How do I make repeat until blocks and variables work in custom blocks?
You're kinda changing the Y value, not the X, you'd have to change the X value to prevent it from walking through walls…It's kinda working? Now the character can still walk through walls tho.~snap snap~ le crabOH that's why all those other games did that. I'ma try it.
Also, you need to make sure you actually change the location of the sprite before you check again, don't rely on your other script that sets the character to “player y” as your custom block is run without screen refresh, which, well, runs without it refreshing the screen
I swear there was a reason people didn't use thatYes, loops do not work in custom blocks which do not have screen refreshloops very much do work in custom blocks with or without run without screen refresh. If you need it to happen in 1 frame (instantly) then it will need run without screen refresh.
- Malicondi
-
Scratcher
1000+ posts
How do I make repeat until blocks and variables work in custom blocks?
I swear there was a reason people didn't use thatsome people aren't careful and use repeat until <> loops, but break them and they never become untrue so it lags you heavily, which might be why loops are avoided but i use them alot (when necessary)
those 6 long stacked if statements hurt me internally
Last edited by Malicondi (Feb. 21, 2024 21:44:51)
- yadayadayadagoodbye
-
Scratcher
1000+ posts
How do I make repeat until blocks and variables work in custom blocks?
goofyI swear there was a reason people didn't use thatsome people aren't careful and use repeat until <> loops, but break them and they never become untrue so it lags you heavily, which might be why loops are avoided but i use them alot (when necessary)
those 6 long stacked if statements hurt me internally
anyways uhhh scrap what I said in the original reply ill see how I can help with ur thing with a remix, the code seems a bit messy and I feel like it might benefit from certain parts being reorganized
- yadayadayadagoodbye
-
Scratcher
1000+ posts
How do I make repeat until blocks and variables work in custom blocks?
I have created a remix of the project with what I assume you needed. I havn't got all the collision done yet but you could take a look to take inspiration
Idk why this happens it just does
now I remember, people use the nested ifs because for whatever reason its faster. When I use the loop, it somehow takes multiple frames to happen even though its only supposed to take one. It causes no problems but looks kinda weird.I swear there was a reason people didn't use thatsome people aren't careful and use repeat until <> loops, but break them and they never become untrue so it lags you heavily, which might be why loops are avoided but i use them alot (when necessary)
those 6 long stacked if statements hurt me internally
Idk why this happens it just does
- Koamodo975
-
Scratcher
1000+ posts
How do I make repeat until blocks and variables work in custom blocks?
That's what happened. It broke from the repeat until <> loops mixed with variables.I swear there was a reason people didn't use thatsome people aren't careful and use repeat until <> loops, but break them and they never become untrue so it lags you heavily, which might be why loops are avoided but i use them alot (when necessary)
those 6 long stacked if statements hurt me internally
- pythonicKI
-
Scratcher
100+ posts
How do I make repeat until blocks and variables work in custom blocks?
(#10)run without screen refresh loops work as fast as nested if non-run without screen refresh
now I remember, people use the nested ifs because for whatever reason its faster. When I use the loop, it somehow takes multiple frames to happen even though its only supposed to take one. It causes no problems but looks kinda weird.
Idk why this happens it just does
variables do too…?
the custom block probably isn't set to run without screen refresh.
- Malicondi
-
Scratcher
1000+ posts
How do I make repeat until blocks and variables work in custom blocks?
run without screen refresh loops work as fast as nested if non-run without screen refreshin most cases, run without screen refresh is faster than nested ifs btw
variables do too…?
the custom block probably isn't set to run without screen refresh.
- Discussion Forums
- » Help with Scripts
-
» How do I make repeat until blocks and variables work in custom blocks?