Discuss Scratch

AlveKatt
Scratcher
94 posts

Possible float problem

Sometimes, when I fly around in this little game I have made, variables jump to “infinite value”. The background graphics started to flicker like crazy, and when I tried to find the problem I saw that my speed variable didn't have value, instead it said “-infinit v”.

The speed changes as a function based on what way you are going and which way you are facing. Could it be that this sometimes produces too large floats? And if so shouldn't you expect the client automatically round off big floats?

http://beta.scratch.mit.edu/projects/10066520/#player

Last edited by AlveKatt (March 2, 2013 16:31:51)

AlveKatt
Scratcher
94 posts

Possible float problem

I tried flooring the value that controls the speed, I made a screenshot, but I don't have a hosting service at the moment.

Strangely, I still get “infinite v”.

It reproduces reliably every time I Start turning while standing still, and press the forwards key while still turning.

Last edited by AlveKatt (March 7, 2013 19:39:12)

Lightnin
Scratcher
1000+ posts

Possible float problem

Wow, weird one! I've asked some colleagues about this - hopefully we'll sort it out soon.
Lightnin
Scratcher
1000+ posts

Possible float problem

AlveKatt wrote:

I tried flooring the value that controls the speed, I made a screenshot, but I don't have a hosting service at the moment.

Strangely, I still get “infinite v”.

It reproduces reliably every time I Start turning while standing still, and press the forwards key while still turning.

Can you take a look and search for something that will result in a divide by 0? Infinity is there to show that there's probably an issue with the math.
AlveKatt
Scratcher
94 posts

Possible float problem

Ah, yeah, there would be a divide by zero, I can tell you that without looking at the code. Let me put in some code to avoid that and see what happens! The speed variable is 0 when you are standing still, and I have a division on it to scale the speed. So I need a if Speed > 0 block around every place where speed is divided then?

Thanks!

Though, I thought dividing by 0 would get you 0?
AlveKatt
Scratcher
94 posts

Possible float problem

I don't get it. Having if separated from 0 didn't work…
AlveKatt
Scratcher
94 posts

Possible float problem

There were a lot of places where speed was divided. I had an epiphany today though, and redid the whole asteroidish physics engine. I had made it a hundred times more complex than I need to. (From about nine huge scripts to two smallish ones.) I made sure no divisions by zero occurs in the new code.
Lightnin
Scratcher
1000+ posts

Possible float problem

AlveKatt wrote:

There were a lot of places where speed was divided. I had an epiphany today though, and redid the whole asteroidish physics engine. I had made it a hundred times more complex than I need to. (From about nine huge scripts to two smallish ones.) I made sure no divisions by zero occurs in the new code.

Awesome! And I trust you aren't getting infinity / things are working well?

Those epiphanies, btw, are the kind of learning we hoped would occur for people using Scratch when we designed it. It's a very powerful kind of learning that doesn't usually happen with worksheets, or other “rote” educational strategies.
AlveKatt
Scratcher
94 posts

Possible float problem

Lightnin wrote:

AlveKatt wrote:

There were a lot of places where speed was divided. I had an epiphany today though, and redid the whole asteroidish physics engine. I had made it a hundred times more complex than I need to. (From about nine huge scripts to two smallish ones.) I made sure no divisions by zero occurs in the new code.

Awesome! And I trust you aren't getting infinity / things are working well?

Those epiphanies, btw, are the kind of learning we hoped would occur for people using Scratch when we designed it. It's a very powerful kind of learning that doesn't usually happen with worksheets, or other “rote” educational strategies.

Nice. Though, I must admit I am not part of the targeted demographic. I am a 32 year old who just loves it anyway. Despite my age, I have Scratch to thank for a lot. It taught me the basics of scripting, and I used that knowledge to learn the Second Life Scripting language and now Javascript at my internship.

Powered by DjangoBB