Computer Science Canada Flexible Arrays |
Author: | Mr. T [ Sun Oct 23, 2005 5:10 pm ] | ||
Post subject: | Flexible Arrays | ||
In my jezzball game, I made the parameters of Mouse.Where ( ) as elements of a flexible array. I did this with the hope that every time I would click the screen, the array would add an element to itself, and a new bar would be drawn without deleting the previous. My issue is that the flexible array doesnt seem to be doing anything(previous bar is deleted every time a new bar is drawn). Can anyone see why?
|
Author: | jamonathin [ Sun Oct 23, 2005 5:49 pm ] | ||
Post subject: | |||
Well pwned. You're in kind of a mess now. You see, you dont want to make the Mouse.Where variables flexible, you want to make the boxes flexible and the boolean variables flexible and whatnot. It should also be in a record now that theres going to be more than one box. What you should be doing for this is: Whenever the mouse is clicked, add 1 to the upper of these variables: Xvalues of box. Yvalues of box. All the 'horizontalBar' and 'barXFinished1' things that you have scattered throughout your program. And even the variables that change the size of the box (make it grow till the edge). All of this should be done in a for loop where:
Since your program isn't too huge. I suggest starting over. Copyb all of the techniques that you used, but put them into flexible records. Repitition is Good. |
Author: | Mr. T [ Sun Oct 23, 2005 7:07 pm ] |
Post subject: | Alex's Opinion |
Should i stick a for loop around the entire wall creating portion of the code? Or should i make individual for loops around each of the if statements? [ for i: 1..upper(wallArray) ] |
Author: | jamonathin [ Sun Oct 23, 2005 7:39 pm ] | ||||
Post subject: | |||||
If your going to stick with the same layout as you did for the single wall, then you should have all this in a for loop of ( i : 1 .. upper(wall) )
Now here's how you put this into a flexible record
Then in that whole if statement, you would change all of your variable names to (ex. using 'barXstore') ' wall(i).barXstore := whatever ' I'll gladly help you along the way, but i wont do it for you . You'll learn much more trying it out yourself. Just ask when ur stuck (i'll usually respond ) |
Author: | Mr. T [ Sun Oct 23, 2005 9:05 pm ] | ||
Post subject: | Alex's Opinion | ||
Alright here's the updated flexible array code... but i get a "variable has no value" error for wallArray (a).barXFinished1 and wallArray (a).barXFinished2 when I try to assign them a value (possibly because their values get assigned inside an if statement). Anyways, here's the code.
|
Author: | jamonathin [ Mon Oct 24, 2005 6:00 am ] | ||
Post subject: | |||
What you have to do, is right after the mouse is clicked, before the program can get to any other 'if' statements, you have to assign values to the 'Store' variables and whatnot. And forthose 'Finished' variables, just set them to a default value before you enter the loop. So right after this statement:
set values for the boxes. |
Author: | Mr. T [ Mon Oct 24, 2005 8:50 am ] | ||
Post subject: | Alex's Opinion | ||
I thought I had already assigned them a value:
|
Author: | jamonathin [ Mon Oct 24, 2005 10:44 am ] | ||||||||
Post subject: | |||||||||
Yeah, for some reason i though left was right, dont ask, lol. . . But what the problem then is here:
and the fact that your for loop goes from
Well you just added one to wallArray, so now there's two of em. And there's no value for the second (new) wallArray's, so when the for loop goes through the second time, its like wtf mayte, wheres the value? So what i suggest doing is change you var statement to 1 .. 0 of, like this
and changing the new element to look like this, rather than was it was before.
Now, when you add that new element, thats where you may have to set default values for the other variables. And the for loop wont even run if it is 'a: 1 .. 0' try that out. |
Author: | Mr. T [ Mon Oct 24, 2005 2:05 pm ] | ||
Post subject: | Alex's Opinion | ||
Alright, the program runs now without getting a "var has no value error." But now when you click nothing happens; the bar doesn't draw (no Turing error, though). It seems like solving one problem only creates another. Here's the updated code:
|
Author: | jamonathin [ Tue Oct 25, 2005 11:56 am ] | ||
Post subject: | |||
Ok now the bars are drawn. What happened was, you were checking in the for loop that ran from ' a : 1 .. upper(wallArray) ' (which is 1 .. 0 default) for when the mouse was clicked. Well, you can never get to that mouse command if teh for loop never runs right? So nothing insdie that for loop could be accessed. I moves that whole 'if' statement outside the for loop. Before i looked for the problem, i could see that you would already run itno future problems. For instance, grow1 and grow2. You never put them into that flexible array, so when ever you click the mouse, grow1 and grow2 restart. And whenever you draw the other walls, you have them draw with grow1 and grow2. But they restart, so that wall never stays there. But the x and y values do because they're in teh flexible array. So i fixed that up. Also, Horizontalbar needs to be in that record as well. So that we know which horizontal bar we're talking about. We dont want 1 variable to represent them all. So that was thrown in as well. I didn't finish everything, because well, thats your job. What you can notice is that they new variable waitBar (kinda like horizontalBar) restricts a new bar from being drawn (1 at a time). But 'waitBar' only goes back to '0' once BOTH bars are drawn. It never will if only one gets hit. Thats where you can reset 'waitBar' in your wall collision thing. Another thing you'll notice is that there's no more collision on the walls. :O! So check that out . Also, change the text that you draw. Kinda messes things up. (maybe draw on another output screen?) So try out those things i said. Good - Luck.
|