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

Username:   Password: 
 RegisterRegister   
 [Tutorial]How to make your own commands, (like drawbox, etc)
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
recneps




PostPosted: Sun Feb 01, 2004 6:46 pm   Post subject: [Tutorial]How to make your own commands, (like drawbox, etc)

Here is how you make your own commands, for use in Turing, like the built in ones, drawbox, drawline, etc. This can even be used for data processing, like calculate(supplyvariablehere)
heres what you do:

First, make a procedure:
code:
procedure draw3dbox


Next, add parameters, they're the things that you put in brackets after the command, eg.

code:

drawline(x,y,x2,y2,clr)%These are parameters, in the brackets.


All the parameters are listed with their type after, separated by commas when being declared with the procedure. So, it now looks like this:

code:

procedure draw3dbox (x1 : int, y1 : int, x2 : int, y2 : int, x3 : int,
        y3 : int, height : int, clr : int)


Next, put the stuff to do inside the procedure, and end it.

code:
procedure draw3dbox (x1 : int, y1 : int, x2 : int, y2 : int, x3 : int,
        y3 : int, height : int, clr : int)
    %Add parameters, like for drawbox, the stuff you put in brackets, (x,y,x2,y2,colour)
    drawline (x1, y1, x2, y2, clr) %put the stuff that the procedure will do, using the
    drawline (x1, y1, x1, y1 + height, clr) %parameter variables above.
    drawline (x2, y2, x2, y2 + height, clr)
    drawline (x1, y1 + height, x2, y2 + height, clr)
    drawline (x2, y2, x3, y3, clr)
    drawline (x3, y3, x3, y3 + height, clr)
    drawline (x2, y2 + height, x3, y3 + height, clr)
    drawline (x1, y1 + height, x1 + (x3 - x2), y1 + height + ((y3 - y2)), clr)
    drawline (x3, y3 + height, x1 + (x3 - x2), y1 + height + ((y3 - y2)), clr)
end draw3dbox


And lastly, call your procedure, with parameters, like you would drawline, etc..

code:

%draw3dbox(x1, y1, x2, y2, x3, y3, height, clr)
draw3dbox (100, 100, 200, 100, 250, 150, 100, 7)


If you are unable to cut and paste broken up code (Smile) then here is the full code i created.

code:

%first, make a procedure.
procedure draw3dbox (x1 : int, y1 : int, x2 : int, y2 : int, x3 : int,
        y3 : int, height : int, clr : int)
    %Add parameters, like for drawbox, the stuff you put in brackets, (x,y,x2,y2,colour)
    drawline (x1, y1, x2, y2, clr) %put the stuff that the procedure will do, using the
    drawline (x1, y1, x1, y1 + height, clr) %parameter variables above.
    drawline (x2, y2, x2, y2 + height, clr)
    drawline (x1, y1 + height, x2, y2 + height, clr)
    drawline (x2, y2, x3, y3, clr)
    drawline (x3, y3, x3, y3 + height, clr)
    drawline (x2, y2 + height, x3, y3 + height, clr)
    drawline (x1, y1 + height, x1 + (x3 - x2), y1 + height + ((y3 - y2)), clr)
    drawline (x3, y3 + height, x1 + (x3 - x2), y1 + height + ((y3 - y2)), clr)
end draw3dbox
%This will therefore draw a 3dbox when you use:
%draw3dbox(x1,y1,x2,y2,x3,y3,height,colour)
draw3dbox (100, 100, 200, 100, 250, 150, 100, 7)
%Voila. This took me a while to get the top portioins angled right,
%and they still look a little weird, oh well :)


Enjoy!
Sponsor
Sponsor
Sponsor
sponsor
Paul




PostPosted: Sun Feb 01, 2004 6:49 pm   Post subject: (No subject)

Thats REALLY good! I haven't thought about it like that before, thanx, I'll be using this one.
shorthair




PostPosted: Sun Feb 01, 2004 6:49 pm   Post subject: (No subject)

Hate to break it to ya but thats not how you make your own commands , because if you do that , and then onpen a new program and try to call it , your gonna get an error , unless you include hat file at hte top in which it is located , you wanna make your ow ncommands , you use classes , its what turing is built on , sorry to sound harch but this is misleading , this is jsut a basic procedure and is not how drawbox or drawline is called at all , take a quick look in th ehelp file about classes
recneps




PostPosted: Sun Feb 01, 2004 6:51 pm   Post subject: (No subject)

OK, to clarify, Since im a newbie, as said by shorthair there, THIS MUST BE DECALRED AT TOP OF PROGRAM TO CALL IT. There Smile
Paul




PostPosted: Sun Feb 01, 2004 6:58 pm   Post subject: (No subject)

I know it is a procedure, but I still found it useful.
recneps




PostPosted: Sun Feb 01, 2004 7:00 pm   Post subject: (No subject)

Just had to clear that up. Smile
shorthair




PostPosted: Sun Feb 01, 2004 7:06 pm   Post subject: (No subject)

well to clear things up , programs are meant to be writtin like that , your main should be tiny , sorry to spam your thread with my stuff but , my blackjack ( 3000 ) lines had a 40 line main program , cuase everything was procedures , that way you can make multi app , and multi game programs , procuders make sode clean , you should b eusing them wher eever ya can , but to learn propper command making , take a look at classes
Cervantes




PostPosted: Sun Feb 01, 2004 7:52 pm   Post subject: (No subject)

spencer if you want to keep going along the lines you've started you should write tutorials for process and function

don't kill me shorthair Neutral
Sponsor
Sponsor
Sponsor
sponsor
shorthair




PostPosted: Sun Feb 01, 2004 7:59 pm   Post subject: (No subject)

nope not at all , i jsut found hte post misleading , adding those would be agood ideas, but i hate to flame again spencer , but adding in complex funstions and procedures would be good aswell , add in hte fact that vars inside them are no good outside hte procedures and functions and that processes are mostly useless,
recneps




PostPosted: Mon Feb 02, 2004 3:44 pm   Post subject: (No subject)

This is to show people an easier way than cut and paste if they are doing same thing over again, and just changing number Smile
Cervantes




PostPosted: Mon Feb 02, 2004 6:12 pm   Post subject: (No subject)

its definately a good tutorial to post, just, as shorthair said, the name is slightly misleading Confused
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  [ 11 Posts ]
Jump to:   


Style:  
Search: