Posted: Fri Nov 21, 2003 5:29 pm Post subject: Tidbits and Tricks for programming
Here is just a collection of tricks and shortcuts you can use when programming, I knew it helped me alot. Anyways, anyone else with anything to add, please share too.
Declaring Picture Files
I constantly see alot of people declaring picture files like this:
this is really a waste of time, I mean who cares if your name your picture strawberry? It's the program that they care about, so next time you need to import tons of pictures do it like this:
first, name all your pictures "pic1.bmp", "pic2.bmp", "pic3.bmp", "pic4.bmp" ... "pic35.bmp"
then declare an array of variables:
code:
var picID :array 1..35 of int
and run a for loop like this:
code:
for i : 1 .. 35
picID := Pic.FileNew ("pic" + intstr(i) + ".bmp")
end for
this cuts all your picture declaring into 4 lines total. Just make sure you have a textfile or some sort to tell you what each picture is.
Sponsor Sponsor
rizzix
Posted: Fri Nov 21, 2003 6:14 pm Post subject: (No subject)
Emulating two dimensional dynamic arrays in Turing
(there are no two dimensional dynamic arrays in turing)
assumptions:
the array begins with 0 for row and column index
the two dimensional array we are to emulate is not of an irregular shape (this is possible in languages like Java) but of a rectangular (matrix) shape.
solution:
let y be the index for the row count
let x be the index for the column count
then the location of [y][x] in a one dimensional array:
y * NumberOfColumns + x
what does this mean?
var arr : flexible array 0 .. 0 of int
new arr, 99
- notice the total # of elements (or area) in the 2 dimensional array is 100 = the # elements in the one dimensional array
now to get the [2][5] element from this array
x := 5
y := 2
value := arr(y * 10 + x)
Andy
Posted: Fri Nov 21, 2003 7:06 pm Post subject: (No subject)
u lucky turing kids with lower boundry of arrays...
Dan
Posted: Sat Nov 22, 2003 1:27 am Post subject: (No subject)
dodge_tomahawk wrote:
u lucky turing kids with lower boundry of arrays...
why whould you need that? i think you are refuring to how C and othe languges only have [num] for array. but if you think about it you realy dont need a starting and end point for them, since realy they are just the same but with difrent numbers for the index.
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Mazer
Posted: Sat Nov 22, 2003 8:47 am Post subject: (No subject)
i thought dodge meant to say upper boundary of arrays. like, in turing you could say
code:
put upper (myArray)
to see how high the array went. but in c++ you need a variable to keep track of the upper boundary, or just remember it yourself. (unless there's some other way that i was not made aware of)
rizzix
Posted: Sat Nov 22, 2003 2:50 pm Post subject: (No subject)
actually there is another way
sizeof(arr) / sizeof(arr[0])
that should give u the # of elements
Dan
Posted: Sun Nov 23, 2003 2:41 pm Post subject: (No subject)
oOo, i thougth he was talking about the rang thing turing has.
java has the thing to tell how big an array is too.
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Andy
Posted: Sun Nov 23, 2003 3:41 pm Post subject: (No subject)
in turing, you can just pass an array through a function and use upper to how big it is, in c, you have to shove the size in as well, kinda annoying
Sponsor Sponsor
rizzix
Posted: Sun Nov 23, 2003 7:22 pm Post subject: (No subject)
well u'll love java then
suppose u have an array of type x called element[10] <-- yea 10 elements
in java all u need to do is element.length yep thats right an array is an object in java, just ask it its size!
Tony
Posted: Sun Nov 23, 2003 7:32 pm Post subject: (No subject)
everything is an object in java java kicks ass 8)
and methods such as .toString make debugging really easy
Posted: Sun Nov 30, 2003 9:27 pm Post subject: (No subject)
OK, this has been bugging me for too much.
Here is the best programming trick you will ever need when programming in turing.
Press either F8, F9, or F10
Andy
Posted: Sun Nov 30, 2003 9:44 pm Post subject: (No subject)
F8 is awsome it tells you what to type
Cervantes
Posted: Fri Jan 23, 2004 2:53 pm Post subject: (No subject)
ooh cool never new that one
AsianSensation
Posted: Thu Mar 18, 2004 8:36 pm Post subject: (No subject)
Another programming trick. Don't use processes unless you are really really good and can handle it. So far, only Mazer has successfully used processes for his Evasive Maneuvers game (even then he had to create a draw-check procedure to handle it).
I am seeing way too many kids with action games that are full of processes. They are inaccurate, messes up your View.Update, messes up your collision detection, especially those done with whatdotcolor, and God forbid if you based any part of your program on Time.Elapsed. Processes will ruin it all.
Try a normal loop once in a while. Guess what, the computer draws really really fast, I bet you can't tell that one thing is actually happening before another.
Flashkicks
Posted: Fri May 07, 2004 7:47 am Post subject: (No subject)
Its funny that you say that-bcuz I thought of processes to be really handy so far... but i do indeed see where you are coming from.. The only thing with only sticking to procedures is that you cant really have multiple things happening at once. Hence; i always used a process. I could keep my original procedure running and have a process at the same time.. Unless I am just gonig about things All Wrong ..lol.
Process werk GREAT for keeping music in a game as well