Discuss Scratch

jayscheme
Scratcher
62 posts

math game for my teacher is putting the wrong output

https://scratch.mit.edu/projects/1256324137/
My browser / operating system: Windows NT 10.0, Chrome(edge) 143.0.0.0, No Flash versions detected
im making a math game for my math teacher late at night and i seriously cannot fathom what's happening here
i made my own text system using a sprite from scratcher10898 since scratch doesnt have a default text code, it could at first only support 2 digits so i rennovated it to support 3, it was all going perfectly until I started working on the Yproc, which abolutely demolished the work
it keeps outputting at the wrong spot, the wrong numbers, and the wrong digit placements for ####s sake, i am crying right now because I dont have any idea how to fix any of this
quenmkacctrc
New Scratcher
2 posts

math game for my teacher is putting the wrong output

watch this @griffpatch 's video to help you : https://www.youtube.com/watch?v=BAy0SUnB1J0
Note : I had made a text engine on scratch offline and save to my computer but I deleted it
Arvionyx
New Scratcher
40 posts

math game for my teacher is putting the wrong output

I’m not sure by what you meant by Yproc. you could change the huge chunk of code into as simplier one to help with debugging that does the equation first and set the answer as a variable (e.g answer) and check if the result is the same as the variable. Here is an example of the code for 1 scenario:

when green flag clicked
forever
if <[equation] = [*]> then
set [(answer)] to ((X) * (Y))
end
if <(answer) = [(answer)]> then
Code here
end

If the output of the two variables are wrong it means that the answering code is working and the issue is coming from the way your code is calculating the output.

Last edited by Arvionyx (Dec. 21, 2025 12:03:17)

deck26
Scratcher
1000+ posts

math game for my teacher is putting the wrong output

You have no idea which ‘message1’ receiver is going to run first - the one that sets Y to a random value or the one that calls the custom block to display it. Also your YProc script doesn't move to the right place on screen so Y overwrites X.

Simplest fix is to add a short wait to the message1 receiver in the FONT coding.
10goto10
Scratcher
1000+ posts

math game for my teacher is putting the wrong output

You’re going to want to control the flow of execution. It looks like there is a race condition between two scripts, so, making sure you know what is executed first can help.

In sprite FONT

when I receive [message1 v]
+forever
broadcast [Generate quiz question v] and wait
Xproc::custom
Yproc::custom
queProc::custom
broadcast [Quiz User v] and wait
end

+when I receive [Generate quiz question v] //I added this to get rid of the old clones
delete this clone
Then in sprite “MathHandel”
+when I receive [Generate quiz question v] // used to be when I receive message1
set [que v] to (pick random (12) to (15))
set [X v] to (pick random (-20) to (20))
set [Y v] to (pick random (0) to (9))

when I receive [Quiz User v]
wait (0.1) seconds
ask (join [What is ] (join (X) (join (queTrue) (join (Y) [?])))) and wait
Many things not shown, but,
No changes except to Remove the broadcast at the end of this script. // very important. You don’t want this script to loop


Update: posted my message after I saw deck26’s answer. That is probably all you need to do to fix the timing but in general it’s better to control the flow of execution.

Last edited by 10goto10 (Dec. 21, 2025 14:00:32)

jayscheme
Scratcher
62 posts

math game for my teacher is putting the wrong output

Arvionyx wrote:

I’m not sure by what you meant by Yproc. you could change the huge chunk of code into as simplier one to help with debugging that does the equation first and set the answer as a variable (e.g answer) and check if the result is the same as the variable. Here is an example of the code for 1 scenario:

when green flag clicked
forever
if <[equation] = [*]> then
set [(answer)] to ((X) * (Y))
end
if <(answer) = [(answer)]> then
Code here
end

If the output of the two variables are wrong it means that the answering code is working and the issue is coming from the way your code is calculating the output.
Yproc is the block I made for the Y variable
jayscheme
Scratcher
62 posts

math game for my teacher is putting the wrong output

deck26 wrote:

You have no idea which ‘message1’ receiver is going to run first - the one that sets Y to a random value or the one that calls the custom block to display it. Also your YProc script doesn't move to the right place on screen so Y overwrites X.

Simplest fix is to add a short wait to the message1 receiver in the FONT coding.
Somehow I thought of doing that to every other thing before this post lol
jayscheme
Scratcher
62 posts

math game for my teacher is putting the wrong output

10goto10 wrote:

You’re going to want to control the flow of execution. It looks like there is a race condition between two scripts, so, making sure you know what is executed first can help.

In sprite FONT

when I receive [message1 v]
+forever
broadcast [Generate quiz question v] and wait
Xproc::custom
Yproc::custom
queProc::custom
broadcast [Quiz User v] and wait
end

+when I receive [Generate quiz question v] //I added this to get rid of the old clones
delete this clone
Then in sprite “MathHandel”
+when I receive [Generate quiz question v] // used to be when I receive message1
set [que v] to (pick random (12) to (15))
set [X v] to (pick random (-20) to (20))
set [Y v] to (pick random (0) to (9))

when I receive [Quiz User v]
wait (0.1) seconds
ask (join [What is ] (join (X) (join (queTrue) (join (Y) [?])))) and wait
Many things not shown, but,
No changes except to Remove the broadcast at the end of this script. // very important. You don’t want this script to loop


Update: posted my message after I saw deck26’s answer. That is probably all you need to do to fix the timing but in general it’s better to control the flow of execution.
Yeah you guys are really saving me out here, good thinking having a seperate message for asking and generating (unlike mine lol)
jayscheme
Scratcher
62 posts

math game for my teacher is putting the wrong output

Thanks all of you guys, I'll be renovating the code this night and let you know how it goes, remind me to credit you all!
jayscheme
Scratcher
62 posts

math game for my teacher is putting the wrong output

check it out now

Powered by DjangoBB