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

Username:   Password: 
 RegisterRegister   
 [Tutorial] Arrays of arrays and more arrays
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mwachna




PostPosted: Sat Mar 05, 2005 6:51 pm   Post subject: [Tutorial] Arrays of arrays and more arrays

Ok, so I had this problem, and it was quite complex, and hard to explain, but I found a good way to address the needs of my program. I don't want to be selfish and keep it to myself so I am going to explain them.
I have a bunch of dance moves that I want to be previewed as per user request. The problem that I faced, was that each dance step had a unique amount of frames (or pics that I had to Pic.Draw).

So what do you do? You need to find a way to call upon a dance step, and somehow create a for loop that will limit its self to the frames the dance step has, and then put that into another loop

well lets start with the code, and THEN the explanation.
code:

%"preview" is the int required for Pic.FileNew
var Pics : array 1 .. 10 of array 1 .. 3, 1 .. 100 of int
var Steps : array 1 .. 3, 1 .. 100 of int
proc Preview (Genre : int, Move : int)
loop
    for rep : 1 .. Steps (Genre, Move)
        Pic.Draw (Pics (rep) (Genre, Move), 100, 0, picCopy)
        delay (50)
    end for
    exit when hasch
    end loop
end Preview


And now to use this procedure in the actual program:

code:

var choice1, choice1: int
loop
    getch (choice1) %thanks ;)
    getch (choice2)
    preview (choice1, choice2)
end loop


ok, so Steps is an array that will carry the value of the total frames for each step. The first parameter will indicate the genre, and the second parameter i dentifies which dance step. This is done to maintain organization in the variables. The upper values of 'Pics' and 'Steps' are made up as the largest POSSIBLE value. Not each step has 10 frames to it, however, I have not yet found a way to adjust this so that I'm not using up memory with variables im not going to use. (any suggestions, let me know please)

So when this proc starts, it is given both the genre and the specific move that is being selected. With this information, it calls upon Step(x,y) to determain how many frames it needs to loop through. Then it makes a for loop that will display each pic. As the first value of 'Pics' increases it displays the next pic in the sequence. When the last pic is displayed, the for loop is completed, and then the loop starts the for loop up again.

This can be used for many different functions, and it is very nifty for cleaning up some ugly if statements, and keep things neat and tidy.

-matt
-Go T-Cats!-
Sponsor
Sponsor
Sponsor
sponsor
person




PostPosted: Sat Mar 05, 2005 8:47 pm   Post subject: (No subject)

nice tutorial!! :d

btw: look at ur line with getch
ssr




PostPosted: Sat Mar 05, 2005 9:43 pm   Post subject: (No subject)

Yes, thats a nice tutorial
Smile
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: