Arrays in games??
Author |
Message |
hobojoehobo
|
Posted: Wed Mar 24, 2010 5:38 pm Post subject: Arrays in games?? |
|
|
What is it you are trying to achieve?
Put arrays into a loop
What is the problem you are having?
Arrays cannot work in my game for the red boxes
Describe what you have tried to solve this problem
1. Put array and for in loop and boxes did not appear
2. Made a rough file with an array and made boxes appear, but as they moved it flashed even with View.Update
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
found on http://compsci.ca/v3/viewtopic.php?p=210463#210463
Please specify what version of Turing you are using
4.0.5
Note: If you look at the program, i removed arrays and did not use a single one, just used a bunch of variables |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
Turing_Gamer
![](http://compsci.ca/v3/uploads/user_avatars/8617055374bcc8b48c6d4f.png)
|
Posted: Thu Mar 25, 2010 7:25 am Post subject: RE:Arrays in games?? |
|
|
All you do for 'array' command is define the variable. Then you use 'for' or regular loops to assign each arrayed varriable an interger, string, etc.
Example:
Turing: | var xbullets : array 1 .. 20 of int
for i : 1 .. 20
xbullets (i) := - 10
end for
%etc...
|
Have you learned arrays before? |
|
|
|
|
![](images/spacer.gif) |
copthesaint
![](http://compsci.ca/v3/uploads/user_avatars/15853548854c9c056fda48d.jpg)
|
Posted: Thu Mar 25, 2010 10:57 am Post subject: Re: Arrays in games?? |
|
|
About arrays: An array is a type of variable but instead of just initializing 1 varable of one type *eg( var x : type := init
value), you create many variables *eg(var x : array #..# of type := init (init Value) ), So the array is kinda like creating a variable many times, but you keep one name, here is an example of both, and why it would be better to use an array.
Turing: | var x1,x2,x3,x4,x5 : int
x1 := 5
x2 := 10
x3 := 15
x4 := 20
x5 := 25
drawfillbox (x1, 0, maxx, maxy, blue)
drawfillbox (x2, 0, maxx, maxy, red)
drawfillbox (x3, 0, maxx, maxy, black)
drawfillbox (x4, 0, maxx, maxy, yellow)
drawfillbox (x5, 0, maxx, maxy, white) |
Now both programs do the same thing, but using an array in more efficient coding, and really can shorten the amount of lines used. |
|
|
|
|
![](images/spacer.gif) |
hobojoehobo
|
Posted: Thu Mar 25, 2010 4:20 pm Post subject: Re: Arrays in games?? |
|
|
Yea i know about how to use arrays...
I've used it in class but it was stuff that were simple and it was more of a program getting different employees names and their wages and stuff ( just as homework)
But, when i tried actually putting an array in my game, i made an array of redBoxX and redBoxY as well as redChange
Then before the Red Boxes Movement i had an for and end for at the end. But when i did this, it did not create the boxes..
And as i said before i just took that piece into a new file and it displayed it with a flash effect even with View.Update....
Right now i just need help determining where i should put the for and end for commands |
|
|
|
|
![](images/spacer.gif) |
USEC_OFFICER
![](http://compsci.ca/v3/uploads/user_avatars/16624966004bb548179e82e.png)
|
Posted: Thu Mar 25, 2010 5:43 pm Post subject: RE:Arrays in games?? |
|
|
Showing the code might help us help you. We really won't know where to put the for/end for unless we can see the code. Could you post your latest version please? |
|
|
|
|
![](images/spacer.gif) |
copthesaint
![](http://compsci.ca/v3/uploads/user_avatars/15853548854c9c056fda48d.jpg)
|
Posted: Thu Mar 25, 2010 5:46 pm Post subject: RE:Arrays in games?? |
|
|
Heres something better, straight out there, you dont post source code, we dont help. We arnt any staff memebers or anything, so make this easier on us lol.
yea sure we have your program, BUT ADD NEW CODE YOUR HAVING TROUBLE WITH!
then someone will help you. |
|
|
|
|
![](images/spacer.gif) |
USEC_OFFICER
![](http://compsci.ca/v3/uploads/user_avatars/16624966004bb548179e82e.png)
|
Posted: Thu Mar 25, 2010 8:16 pm Post subject: RE:Arrays in games?? |
|
|
For some reason, I got a good cop/bad cop vibe there. To continue with this vibe, I'll offer +Karma if you post the source code. (Latest version please) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|