Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Arrays in games??
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
hobojoehobo




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Mar 24, 2010 5:48 pm   Post subject: RE:Arrays in games??

Possibly checked out the array tutorials linked to from the Turing Walkthrough ?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Turing_Gamer




PostPosted: 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?
copthesaint




PostPosted: 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)


Turing:
var x : array 0..4 of int := init (5,10,15,20,25)
for i : lower (x) .. upper (x)
drawfillbox (x (i), 0,maxx,maxy,Rand.Int (0,11))
end for


Now both programs do the same thing, but using an array in more efficient coding, and really can shorten the amount of lines used.
hobojoehobo




PostPosted: 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
USEC_OFFICER




PostPosted: 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?
copthesaint




PostPosted: 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.
USEC_OFFICER




PostPosted: 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)
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: