
-----------------------------------
Mr. T
Sat Aug 12, 2006 10:33 am

Falling Balls
-----------------------------------
I want the balls in this programing to fall.  I believe that the error is occuring in the whatdotcolour part of the code.  Can someone please tell me what I'm doing incorrectly?

View.Set ("offscreenonly")

var itemI, itemQ : array 1 .. 15 of int
procedure itemInitialization
    for i : 1 .. 15
        for q : 1 .. 30

            for a : 1 .. 15
                itemI (a) := Rand.Int (1, 15)
                itemQ (a) := Rand.Int (1, 30)
            end for

        end for
    end for
end itemInitialization

var fallBool : boolean := false
proc drawItem (fall : int)
    for a : 1 .. 15
        drawfilloval (((itemI (a) - 1) * 20) + 10, (((itemQ (a) - 1) * 10) + 5) - fall, 2, 2, black)
%Problem lies in the if statement below
        if whatdotcolour (((itemI (a) - 1) * 20) + 10, (((itemQ (a) - 1) * 10) + 5) - fall) = white then
            fallBool := true
        end if
    end for
end drawItem

itemInitialization

var itemFall : int := 0
loop

    delay (100)
    View.Update
    cls

    drawItem (itemFall)

    if fallBool = true then
        itemFall += 10
    end if

end loop

-----------------------------------
Cervantes
Sat Aug 12, 2006 10:39 am


-----------------------------------
your itemInitialization procedure is very inefficient. The first two for loops do nothing. Eliminate them.

The reason the balls don't fall has nothing to do with the whatdotcolour lines you pointed out. Rather, they don't fall because you never changed any variables. You need to decriment itemI (a) or itemQ (a). All you've done is draw them a few pixels away from their starting spots.

Use descriptive variable names. What in the world is I and Q? Somehow I and Q don't give me the idea of x and y coordinates.

Use records, instead of parallel arrays.

-----------------------------------
Mr. T
Sat Aug 12, 2006 10:43 am

Alex's Opinion
-----------------------------------
I do have an increment.  Check the main loop.  fallItem +=10 when fallBool = true.  fallBool=true under the condition set by the whatdotcolour if statement.  Furthermore, I know that the whatdotcolour if statement is causing the problem because if you take it out, and only have fallBool=true, then the balls DO fall.

-----------------------------------
Cervantes
Sat Aug 12, 2006 2:42 pm


-----------------------------------
Ah, so you do. Most of my reply was in response to your initial post (which you deleted), which didn't have such an incriment (or even this whatdotcolour stuff!) Arr!

I'll point out that you only have one fallBool variable, so either they all fall, or none do. Also, since it is never ever set to false except at initialization, if one ball statisfies the whatdotcolour condition to fall, then they all fall.

So this must mean that none of the balls satisfy the fall condition. This might have something to do with the fact that you View.Update, then cls, then do your whatdotcolouring. Try changing the order of these things. I'd recommend moving the View.Update and cls stuff to the end of the loop (it makes more sense, doesn't it?). So it becomes: call procedure; View.Update; delay; cls.

I don't have Turing on this computer, so you'll have to try some different things and report your successes/failures back here.

-----------------------------------
Mr. T
Sat Aug 12, 2006 3:10 pm

Alex's Opinion
-----------------------------------
Sticking the cls and View.Update at the end worked!  So that each ball falls on its own, I'll make fallBool into an array.  Thanks for the help.

-----------------------------------
Mr. T
Sat Aug 12, 2006 3:28 pm

Alex's Opinion
-----------------------------------
Ok, each ball (and boolean) is an element in an array.  Nonetheless, the balls still fall at the same time.  Any ideas as to why?
View.Set ("offscreenonly")

var itemI, itemQ : array 1 .. 15 of int
procedure itemInitialization
    for a : 1 .. 15
        itemI (a) := Rand.Int (1, 15)
        itemQ (a) := Rand.Int (1, 30)
    end for
end itemInitialization

var fallBool : array 1 .. 15 of boolean
proc drawItem (fall : array 1 .. 15 of int)
    for a : 1 .. 15
        drawfilloval (((itemI (a) - 1) * 20) + 10, (((itemQ (a) - 1) * 10) + 5) - fall (a), 2, 2, black)
        %Problem lies in the if statement below
        if whatdotcolour (itemI (a), itemQ (a)) = white then
            fallBool (a) := true
        end if
    end for
end drawItem

itemInitialization

var itemFall : array 1 .. 15 of int
for i : 1 .. 15
    itemFall (i) := 0
end for

loop
    drawfillbox (33, 424, 282, 55, blue)
    drawItem (itemFall)
    for a : 1 .. 15
        if fallBool (a) = true then
            itemFall (a) += 10
        end if
    end for

    delay (100)
    View.Update
    cls
end loop

-----------------------------------
[Gandalf]
Sat Aug 12, 2006 5:46 pm


-----------------------------------
Here's some incentive to use flexible arrays.  If you do that, and start it off with no balls in the array, you can then add a timer which, when elapsed, spawns a new ball.  This gives you control over the spawn rate and over how many balls you will allow in total.

-----------------------------------
Mr. T
Sat Aug 12, 2006 5:47 pm

Alex's Opinion
-----------------------------------
I'm not trying to accomplish that.  Rather I want a ball to fall ONLY when it is touching white.

-----------------------------------
Cervantes
Sat Aug 12, 2006 7:42 pm

Opinion of Cervantes:
-----------------------------------
Of course they all fall at the same rate: 10 pixels per loop. That's a hardcoded value. And as soon as the whatdotcolour condition for a particular ball to fall is met, it will fall forever. There's no way to turn falling off.


Use descriptive variable names. What in the world is I and Q? Somehow I and Q don't give me the idea of x and y coordinates.

Use records, instead of parallel arrays.
This still applies.

-----------------------------------
Mr. T
Sat Aug 12, 2006 7:49 pm

Alex's Opinion
-----------------------------------
No, you're not understanding. The whatdotcolour if statement places a condition on the balls. The balls that are within the blue square SHOULD NOT fall, whereas the rest of the balls SHOULD. I don't know what's wrong with the whatdotcolour if statement?!

-----------------------------------
[Gandalf]
Sat Aug 12, 2006 8:15 pm


-----------------------------------
Mr. T, that this is a situation where you should be using records instead of parallel arrays (itemI, itemQ).  That would make your code much more readable (added on to more descriptive naming), which in turn would make it easier for you to code and us to help you.

As for the reason why your whatdotcolour isn't working, I looked at it for a bit and couldn't figure it out.  Possibly as a result of your slightly cryptic, and more than slightly disorganized code.  My guess is that it's something to do with the proper colour not being detected because of the order in which things are drawn.

Really, general coding practices are more important than random problems with your code not working.  That is where you must improve.

-----------------------------------
TheOneTrueGod
Sat Aug 12, 2006 9:28 pm


-----------------------------------
Nowhere in your code is fallBool set to false... Before you continue with this project, STOP, and do cervantes'/gandalf's suggestions...  It'll save you a tonne of work later on, and if you keep using names and coding practices like this, people may just refuse to help you because your code is unreadable...

-----------------------------------
TokenHerbz
Sat Aug 12, 2006 11:28 pm


-----------------------------------
Here bud, have a look at this....

I hope i didn't make it to confusing lol, i tend to do that alot :(


setscreen ("Graphics:maxx;maxx, title: Test")
View.Set ("offscreenonly")

%%id try using a class for this, but its to show Mr.T about records

var mx, my, mb : int %%my mouse vars i want to use.
var box_size : int := 20 %going to draw a box (you center it yourself if you want)

type balls :
    record
        x, y : int
        size : int
        vy : int %%how fast it will fall
        check : boolean %%%%%oooooooooo!!!!!
        distance : int      %%im going to use this to see how far from top it is
        %%can have more, like color, etc:
    end record

%%on your code you have a set amount of balls at one givin time?
%%i will mimic this, but id use a flexable array with a timer
%% too add balls the longer you play :)
var ball : array 1 .. 15 of balls %%makes an array with the variables in the record

%%now we can start to initialize everything like you have done.
proc spawn_balls
    for i : 1 .. upper (ball)
        ball (i).size := Rand.Int (1, 10)
        ball (i).distance := 0  %%hasn't moved any pixles
        ball (i).x := Rand.Int (10, maxx - 10)
        ball (i).y := maxy %%set at the top
        ball (i).vy := Rand.Int (-5, -1)
    end for
end spawn_balls

fcn allowable_boundries (num : int) : boolean
    Mouse.Where (mx, my, mb) %too see where my mouse is
    %%mb not needed unless you want to add smothing for it

    %%number, for the specific ball
    if ball (num).x >= mx and ball (num).x = my and ball (num).y 