
-----------------------------------
AsianSensation
Fri Nov 21, 2003 5:29 pm

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:
var picID: array 1..20 of int

picID (1) := Pic.FileNew ("Apple.bmp")
picID (2) := Pic.FileNew ("Orange.bmp")
picID (3) := Pic.FileNew ("Strawberry.bmp")
picID (4) := Pic.FileNew ("Starfruit.bmp")
.
.
.
picID (5) := Pic.FileNew ("Avocado.bmp")
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: var picID :array 1..35 of int
and run a for loop like this:
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.

-----------------------------------
rizzix
Fri Nov 21, 2003 6:14 pm


-----------------------------------
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
Fri Nov 21, 2003 7:06 pm


-----------------------------------
u lucky turing kids with lower boundry of arrays...

-----------------------------------
Dan
Sat Nov 22, 2003 1:27 am


-----------------------------------
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.

-----------------------------------
Mazer
Sat Nov 22, 2003 8:47 am


-----------------------------------
i thought dodge meant to say upper boundary of arrays. like, in turing you could say

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
Sat Nov 22, 2003 2:50 pm


-----------------------------------
actually there is another way :)

sizeof(arr) / sizeof(arr[0])

that should give u the # of elements

-----------------------------------
Dan
Sun Nov 23, 2003 2:41 pm


-----------------------------------
oOo, i thougth he was talking about the rang thing turing has.

java has the thing to tell how big an array is too.

-----------------------------------
Andy
Sun Nov 23, 2003 3:41 pm


-----------------------------------
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

-----------------------------------
rizzix
Sun Nov 23, 2003 7:22 pm


-----------------------------------
well u'll love java then :)

suppose u have an array of type x called elementelement.length yep thats right an array is an object in java, just ask it its size!

-----------------------------------
Tony
Sun Nov 23, 2003 7:32 pm


-----------------------------------
everything is an object in java :D java kicks ass 8)

and methods such as .toString make debugging really easy :D

-----------------------------------
AsianSensation
Sun Nov 30, 2003 9:27 pm


-----------------------------------
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
Sun Nov 30, 2003 9:44 pm


-----------------------------------
F8 is awsome it tells you what to type

-----------------------------------
Cervantes
Fri Jan 23, 2004 2:53 pm


-----------------------------------
ooh cool never new that one :P

-----------------------------------
AsianSensation
Thu Mar 18, 2004 8:36 pm


-----------------------------------
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
Fri May 07, 2004 7:47 am


-----------------------------------
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 :shock: ..lol.  

Process werk GREAT for keeping music in a game as well ;)

-----------------------------------
Dan
Fri May 07, 2004 12:00 pm


-----------------------------------
U should only uses proces when they are needed, it dose not make scen to uses them rather then a procedure. And the avg new user dose not use them right b/c they do not understand the conspects of multy treading.

-----------------------------------
Cervantes
Fri May 28, 2004 4:23 pm


-----------------------------------
when you're typing out your code:
if you've typed this:

for n : 1 .. 100

hit ctrl + enter, it will skip a line and type end for.
it even works if you've just typed

for

it also works for ifs and loops and functions and whatnot.

EDIT: only works with Turing 4.0.5

-----------------------------------
Andy
Thu Jun 03, 2004 8:32 pm


-----------------------------------
wow.. thats cool... very useful for me cuz when i program in turing, i like to finish my loops/if statements/procs just so the indent will look prettier.. thx

-----------------------------------
wtd
Mon Sep 27, 2004 2:39 pm


-----------------------------------
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

C++ templates and runtime type inferencing make this much easier.

#include 

template 
void println_all(T (&arr)[N])
{
	for (int i = 0; i < N; i++)
	{
		std::cout 