Posted: Tue Oct 04, 2005 11:03 pm Post subject: FLEXABLE ARRAYS!
this is a classic example of my code screwing up cause i lack knowledge or these arrays which can change size...
Anyways, Help me out please...
code:
%%UFO GAME%%
setscreen("Graphics:300;150")
%%Variables
var counter: int:= 1
var game: boolean := false
var x, y: int %Ball
var speed: int := 0 %Ball other speed
var vx, vy: int %ball direction
var sp,sz: int %ball speed/size
var num: int := 1 %number of obsticles
var x1, y1: flexible array 1 .. 1 of int %obsticle
var vx1, vy1: array 1 .. 20 of int %obsticle direction
var sp1,sz1: array 1 .. 20 of int %obsticle speed/size
var level: int
var ship: array char of boolean
%%Declare
%ball
x := 20
randint(y,20,80)
sp := 1
sz := 5
vx := sp
vy := sp
%obsicle
for i: 1 .. num
x1(i) := 280
randint(y1(i),11,139)
sp1(i) := 1
sz1(i) := 10
vx1(i) := sp1(i)
vy1(i) := sp1(i)
end for
%%Intro
put "Hi, wecome to a UFO game"
put "Just avoid the obsticles"
put "Good luck"
put "More to come later"
Input.Pause
cls
%%Game%%
loop
%move ship
Input.KeyDown(ship)
if ship (KEY_UP_ARROW) then
y := y + vy
end if
if ship (KEY_DOWN_ARROW) then
y := y - vy
end if
if ship (KEY_RIGHT_ARROW) then
x := x + vx
end if
if ship (KEY_LEFT_ARROW) then
x := x - (vx + 1)
end if
%boundry
if x <= 0 then
x *= -1
end if
if x >= 300 then
x *= -1
end if
if y <= 0 then
y *= -1
end if
if y >= 150 then
y *= -1
end if
for i: 1 .. num
x1(i) := x1(i) - vx1(i) - speed
%%Colistion
if x+sz >= x1(i)-sz1(i) and x-sz <= x1(i)+sz1(i) and y+sz <= y1(i)+sz1(i) and y+sz >= y1(i)-sz1(i) and y-sz >= y1(i)-sz1(i) and y-sz <= y1(i)+sz1(i) then
game := true
exit
end if
if x1(i) + sz1(i) <= 0 then
for ii: 1 .. num
x1(ii) := 280
randint(y1(ii),11,139)
sp1(ii) := 1
sz1(ii) := 10
vx1(ii) := sp1(ii)
vy1(ii) := sp1(ii)
num += 1
new x1, num
new y1, num
end for
end if
drawfilloval(x1(i),y1(i),sz1(i),sz1(i),red)
end for
if game = true then
exit
end if
%draw the items
drawfilloval(x,y,sz,sz,black)
delay(5)
cls
end loop
cls
put "Game over"
Yeah this one was slapped together to strengthin my "FLEXABLE ARRAY" skills, and i need help as the FREAKING TUTOREAL IS CRAP!!!
yeah nothing makes sence in that crap, no offence or anything, but its not newb friendly? maybe i just cant understand it... who knows..
Sponsor Sponsor
[Gandalf]
Posted: Tue Oct 04, 2005 11:17 pm Post subject: (No subject)
Cervantes' tutorial is great imo, it seems noob-enough-friendly. Maybe you should first learn everything (or most) before it in the Turing Walkthrough.
Quickly looking at your code, try looking up records too.
TokenHerbz
Posted: Wed Oct 05, 2005 12:34 am Post subject: (No subject)
nah i make it nice for actually codes, like pong, tic tac toe, RPG, etc::
Believe you me i know most of it, just not flexible arrays, its as if i have to make the for flexible to eh?
Well just help me?
[Gandalf]
Posted: Wed Oct 05, 2005 12:51 am Post subject: (No subject)
Well, you will be more likely to get help using more meaninful variable names. Instead of sz, you should be using ballSize, or better yet ball.size (hence the records).
Also, one key problem is that you have the obstacles being flexible, while things like obstacle direction are not. Each obstacle needs this info, so it all needs to be flexible. An easy way of doing this is putting all that data into a record, and making that flexible.
These are just some of the problems with your code.
wtd
Posted: Wed Oct 05, 2005 1:42 am Post subject: (No subject)
And for the love of everything unholy, use whitespace!
code:
x1(i)-sz1(i)
There's no good reason for this, as opposed to:
code:
x1(i) - sz1(i)
Or using Turing convention:
code:
x1 (i) - sz1 (i)
Cervantes
Posted: Wed Oct 05, 2005 3:24 pm Post subject: Re: FLEXABLE ARRAYS!
tokenherbz wrote:
i need help as the FREAKING TUTOREAL IS CRAP!!!
yeah nothing makes sence in that crap, no offence or anything, but its not newb friendly? maybe i just cant understand it... who knows..
My tutorial?
Keep in mind it assumes you have a solid understanding of regular arrays. It also semi- assumes you know something about records, though if you don't you can just skip over the few (one?) parts that require it.
What do you find difficult about it? Have you spent time figuring out how the examples work? Tutorials often aren't going to solidly teach you everything if you read through it quickly once.
tokenherbz wrote:
Well just help me?
We're not obligated to. Ask kindly.
TokenHerbz
Posted: Wed Oct 05, 2005 9:24 pm Post subject: (No subject)
ok Canavas... Please help me... in the future!
2nd off, Please dont tell me to code how you would code, ill code how i please, for short expamles i use QUICK names as to not waste time, and i DO use good names in complex, or longer codes... this goes along the with procs and etc: if i want to make sloppy quick examples to test stuff out, then i will, and i know better to make everything nice and neat, for once again, the longer more complex stuff...
Though i will start to use more records, Any pointers to know when you should use them??? So far i only use them in my RPG... For the hero's and weps, etC: The things i need multiples for..
3rd off, Canavas, i figured it out, i was messing up the for statments...
[Gandalf]
Posted: Wed Oct 05, 2005 10:36 pm Post subject: (No subject)
Make an flexible array of a record as I said above.
If you want people to help you, whether it benefits your example code of not, I suggest making it as easy for them as possible. When having variables like sz, you are encrypting to code, li if ea sid ts.
Sponsor Sponsor
Mr. T
Posted: Wed Oct 05, 2005 10:45 pm Post subject: Alex's Opinion
tokenherbz wrote:
Canavas
Cervantes.
[Gandalf]
Posted: Wed Oct 05, 2005 10:48 pm Post subject: Re: Alex's Opinion
Pwned wrote:
tokenherbz wrote:
Canavas
Cervantes.
Clevernuts
TokenHerbz
Posted: Thu Oct 06, 2005 12:10 am Post subject: (No subject)
ok... my bad on the spelling :S
Um, well ill fidle with it and post what i got tonight if i do it, i might not have time, we will see
I like to meditate, and read up on mind expanding things 1st...
::: E D I T :::
-------------------
BAH!!!!! Fusteration kicks in, tutorial in hand... and im stuck again!
I must say i hate these damn flexible arrays :S
code:
setscreen("Graphics:400;400")
var counter:= 0
var balls : flexible array 1 .. 2 of
record
balls_x_position, balls_y_position: int
balls_x_velocity, balls_y_velosity: int
balls_size: int
end record
for i: 1 .. upper (balls)
balls_size(i) := randint(2,10)
balls_x_position(i) := randint(balls_size,maxx-balls_size)
balls_y_position(i) := randint(balls_size,maxy-balls_size)
balls_x_velocity(i) := randint(-6,0)+3
balls_y_velocity(i) := randint(-6,0)+3
end for
proc spawn_more_balls
if counter = 100 then
for i: 1 .. upper (balls)
new balls, upper (balls) + 1
drawfilloval(balls_x_position(i), balls_y_position(i), balls_size(i), balls_size(i), 7)
end for
counter := 0
end if
end spawn_more_balls
proc move_balls
for i: 1 .. upper (balls)
balls_x_position(i) := balls_x_velocity(i)
balls_y_position(i) := balls_y_velocity(i)
end for
end move_balls
%%%main loop
loop
spawn_more_balls
move_balls
end loop
So What do you see wrong with this?? Please help me??
Anyone???
::: E D I T :::
-----------------
Forgot to add my PS message
P.S. Dear Gandalf, i made GOOD VARIABLE NAMES!!! just for you!
Now i hope you can understand my code, and help me
Over and out
Peace
beard0
Posted: Thu Oct 06, 2005 8:01 am Post subject: (No subject)
Try tracing your program; you'll note that you never leave the spawn more balls procedure. Tracing is generally a good debugging tactic.
Actually, I'm not sure how turing delas with that... does turing allow the upper bound of a for loop to change, if the expression used to define it changes value? Hm... the computer I'm on now doesn't have Turing, so I can't test. Tracing would still be a good idea.
TokenHerbz
Posted: Thu Oct 06, 2005 9:26 am Post subject: (No subject)
it dosn't even run, and the errors are that it says my variables are not declared...
So i looked harder to see that i was missing "int"
code:
var balls : flexible array 1 .. 2 of int
and what now, just as much errors if not more :S
Tony
Posted: Thu Oct 06, 2005 10:54 am Post subject: (No subject)
records are decleared as
Turing:
type variable_name : record
name :string
x :int
y :int endrecord
[Gandalf]
Posted: Thu Oct 06, 2005 2:53 pm Post subject: (No subject)
The record is a variable, so you need to call the record...
code:
balls (i).balls_size := Rand.Int (2, 10)
Or, if you change the code to reflect this new knowledge, a better variable name would be:
code:
ball (i).size := Rand.Int (2, 10)
*edit* Tony, you don't need to make it a type, it can be a variable as well.