1. Dismiss Notice
  2. GOG.com logo

    Thanks to YOUR votes, GOG.com now sells:
    - Sea Dogs - Sea Dogs: Caribbean Tales
    - Sea Dogs: City of Abandoned Ships

    Vote now to add Pirates of the Caribbean to the list!

    Dismiss Notice
  3. Under the Crossbones Podcast

    A Pirate Podcast with Interviews
    Music, Comedy and all things Pirate!

    - Episode Guide - About - Subscribe -
    - Twitter - Facebook - iTunes - Android -
    - Youtube - Fill the Coffers -

    Dismiss Notice
  4. New Horizons logo

    Quick links for PotC: New Horizons
    - Download latest version
    - Wiki - FAQ - Report bugs here
    - ModDB profile

  5. GOF logo

    Quick links for AoP2: Gentlemen of Fortune 2
    - Downloads and info
    - Historical Immersion Supermod
    - ModDB Profile

Dismiss Notice
New to the forum?
Please take a moment to read our Welcome Message and Forum Rules.

PA course on C

Discussion in 'Tutorials' started by Diomed, Jan 1, 2004.

  1. Diomed

    Diomed Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    2,143
    Location:
    Washington D.C
    Don't know anything about C but want to learn? In this thread I will gradually teach C post by post. Let's start oh and email me if you have questions so this thread can be researved for lessons.

    NOTE: THE ` are to fill space
    Compound Assignment operators

    ________________Example_________________Equivilent_____________
    *=```````````total *= 1.25;`````````` total = total *1.25;
    ____________________________________________________________
    / = `````````amt /= factor;````````````amt=amt factor;
    ____________________________________________________________
    %= ````````` days %= 3; ````````````days=days % 3;
    _____________________________________________________________
    += ````````` count += 1;`````````` count =count + 1;
    _____________________________________________________________
    -= ``````````` adjust -= 0.5; ``````````adjust=adjust - 0.5;
    _____________________________________________________________
     
  2. Diomed

    Diomed Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    2,143
    Location:
    Washington D.C
    The Programming Process:

    1. Decide What The Program Is To Do
    2. Use an editor to write and save your programming language instructions. An editor is usualy a word processer (though not as fancy) that lets you create and edit texts. All the popular C compilers include an intergrated editor along with the programming language compiler. All C program file names end in the .C extension.
    3. Compile Program
    4. Check Program for errors
    5. Execute Program
     
  3. Diomed

    Diomed Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    2,143
    Location:
    Washington D.C
    The C program you write is called source code . A compiler takes C source code and translates it into machine language. Computers are made up of thousands of little switches thar are eithor ON or OFF. So eventually all instructions must be given in binary . It is alot eaiser to use a C compliler to convert your c programs into 1s and 0s that represent on and off then to do it manualy.
     
  4. NathanKell

    NathanKell ...

    Joined:
    Jan 1, 1970
    Messages:
    5,265
    Excellent work you're doing! :shock:

    You may want to drudge up, on the old mod forum, the posts on `POTC-C`.
    Wait, wait, let me get the link.

    POTC has some...peculiarities...when it comes to C.

    Ah: http://www.piratesahoy.net/postt744.html

    And, for a (gradually increasing) list of native directives/variable types/functions, see http://pirate.webserver.com.my/files/Natha...Kell/Keywords.c

    Last bit: though I didn't realize it until ALexusB brought it to my attention, POTC /does/ have debugging support. Open engine.ini and set tracefilesoff = 0.
    (it's normally 1).
    Also, make sure debuginfo is set to 1, otherwise it won't work right.

    You can also use the trace() function if you want to log things to the runtime log, but that won't be created unless tracing is on (aka tracefilesoff = 0).
     
  5. Diomed

    Diomed Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    2,143
    Location:
    Washington D.C
    HELPFUL HINT:
    C is not as particular as you might think, most spaces in programs are made so that it is easier for people to see. To make things easier,when programming, add blank lines and indent source code so that it is easier to find what you want and so you can read it like a document.
     
  6. Diomed

    Diomed Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    2,143
    Location:
    Washington D.C
    Ok let's see how things work, this is a command to type into a C compiler editor, once you compile the program and run it, a Message will come up sayin:
    THIS C STUFF IS EASY

    So lets see what we need to type in order to ececute this. Here is the very simple program:

    Code:
    /* Prints a Message on the screen */
    
    #include <stdio.h>
    
    main()
    
    {
    
      printf ("THIS C STUFF IS EASY!n");
    
       return 0;
    
    }
     
  7. Diomed

    Diomed Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    2,143
    Location:
    Washington D.C
    no that's fine. also I meant to do at the top

    Code:
    /* Prints a message on the screen /*
    I had the /* backwards.
     
  8. Captain_Cook

    Captain_Cook Landlubber

    Joined:
    Dec 14, 2003
    Messages:
    315
    Location:
    Europe
    Err, isn't that the idea?

    /* is the start of a comment block, and */ is the end.

    /* this is a comment block */

    /* this will make the compiler start to vomit :S /*
     
  9. Diomed

    Diomed Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    2,143
    Location:
    Washington D.C
    that's right.
     
  10. Diomed

    Diomed Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    2,143
    Location:
    Washington D.C
    Sorry for the delay, So:

    The most important function in C is the main() function. It is a function , not a command, a function is a rutine which comes with C or as you write. A function is a rutine which preforms a task.

    Are you taking notes? 8) Good because this may get Tricky!

    Now all C Programs are made up of one or more Functions each program must always contain the main() function.


    The pareentheses that follow the function are used to distinguish it from a command the following are functions:

    These are functions
    main() calcIt() printf() strlen()

    these are commands:

    return while int if float
     
  11. NathanKell

    NathanKell ...

    Joined:
    Jan 1, 1970
    Messages:
    5,265
    Nit #367:
    int and float are declarations.
     
  12. Diomed

    Diomed Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    2,143
    Location:
    Washington D.C
    You may be right, but my point was to distinguish functions to other text.

    NOTE
    one of the previous functions listed; calcIt() contained uppercase letters, you should generally stay away from upper case letters, however in the case of a name having multiple parts, it is ok and generally helpful to use uppercase letters to distinguish the different words and increase readabillity (spaces aren't allowed in function names) do not type any names in all uppercase, however once in a while it is okay to capitalize a letter.
     
  13. Diomed

    Diomed Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    2,143
    Location:
    Washington D.C
    the main() function, mentioned earlier is as was said the most important function. This is because it is always the first thing the computer reads when starting a program. main() does not have to be the first thing in your program, it marks where the computer begins its execution of the program although it does not have to be the first text in the program, it must be the first function, because the actual execution of the program does not start until main() , any functions mentioned before hand would be useless.


    NEXT:
    the uses of barracks
     
  14. cwineman

    cwineman Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    131
    Not to spoil what you are trying to do in this thread, but maybe it would be better to simply provide links explaining the basics of programming in C. A Google search - such as "c programming language tutorial" - will provide a bunch of links that can explain C.

    I think it would be more useful to use this thread for Q&A for people who have attempted to do a little C hacking for POTC, but are running into problems. Probably problems that are easy for someone with some C programming experience to fix.

    My guess is that there are some people out there that love the game and want to help improve it, but aren't interested in C. I guess what I'm saying is that you are spending alot of time explaining things that have already been explained.

    I think what you are attempting with this thread is great. Your experience, Diomed and NathanKell, with C and with the souce code for POTC will be very useful for people that actually attempt to do some coding, but only the REALLY motivated are gonna give it a try.

    -cwineman
     
  15. Diomed

    Diomed Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    2,143
    Location:
    Washington D.C
    Your point is taken, but in order to mod in POTC you need to know the basics of C, that's what I am trying to teach. Also, answering peoples questions is alot easier when it is in my own words. I am merely tryig to teach a very short course on C for this community. 8)

    -Diomed
     
  16. cwineman

    cwineman Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    131
    Diomed,

    You're right, answering questions in your own words, as a coder(I assume) who enjoys POTC who has looked at the source code, is important. I think its great that you are willing to put forth the effort to do this. There are a handful of people here that run this forum and provide the material here that make this game worth playing. Without you guys I would have shelved this game long ago.

    But, I looked at earlier posts and thought you repeating alot of things that are available on the web. Then I briefly looked at some of the source code. My opinion for this thread is: Don't waste time teaching C. Show people where the juicy parts of the POTC code base are, and help them when they are having trouble making modifications.

    That said, I apoligize if I am off base. I haven't helped so far, but I know some C and I will help if I can. I've enjoyed the game much more from the work that others have done so far.

    -cwineman
     
  17. Diomed

    Diomed Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    2,143
    Location:
    Washington D.C
    I think I see now what you are getting at, in a POTC forum this may seem kind of odd. Your point is well taken, perhaps rather then teaching in so much detail, I can show links which will help with the learning process. As to C in POTC I think NK would be better qualified for that. 8) . I made this thread so that people can get a feel for C before they started the much more difficult POTC modding. I understand that you meant no offense by the way, you can hardly get mad at someone for stating an opinion, especially when there logical! :cheeky

    Diomed
     
  18. cwineman

    cwineman Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    131
    Diomed.

    Cool, you see what I was saying. Only realize, I think in this thread, your input would be as valuable as NK's.

    I think this thread is great idea. I'm just not sure it will very popular. I hope people will take an interest in how the game they are playing works.

    I'm not gonna hold my breath. Either way, if they show up, I will help if I can.
     
  19. Diomed

    Diomed Landlubber

    Joined:
    Jan 1, 1970
    Messages:
    2,143
    Location:
    Washington D.C
    well the thread has 219 views, and I have ony seen it when I post messages. 8)
     
  20. NathanKell

    NathanKell ...

    Joined:
    Jan 1, 1970
    Messages:
    5,265
    And I stand by as well. 8)

    You may want to talk about variable types next (as IIRC in other languages variables can be typeless), noting that POTC instead of char has string, and also POTC's "new" types, objects, refs, and arefs.
     

Share This Page