Author Topic: includes?  (Read 3863 times)

0 Members and 1 Guest are viewing this topic.

Offline Fuzzy168

  • VC:MP Veteran
  • *****
  • Posts: 729
  • Programming since 2011
    • View Profile
includes?
« on: November 13, 2011, 08:32:17 am »
How do i create Includes???
I'm beginning to feel like a Lag God, Lag God

Offline Skirmant

  • Made Man
  • ***
  • Posts: 134
    • View Profile
Re: includes?
« Reply #1 on: November 13, 2011, 12:36:53 pm »
Here's how to write a C style include. Create a file named test.h inside include folder. Add this code inside the file:
 
Code: [Select]
#if defined Test_H // Checks if the Test_H macro is defined
#endif // Ends if the file was attempted of being included twice

#define Test_H // Defines the Test_H macro

public TestFunc() {
printf("TestFunct has been found o:");
}

Inside the main code add:

Code: [Select]
#include <test.h>
Now try calling the function and see how it goes. Cheers :P

Offline stormeus

  • VC:MP Developer
  • VC:MP Veteran
  • *
  • Posts: 1122
    • View Profile
Re: includes?
« Reply #2 on: November 13, 2011, 12:53:40 pm »
Slight correction:
[pawn]
#if defined Test_H // Checks if the Test_H macro is defined
#endif // Ends if the file was attempted of being included twice
[/pawn]

Should be
[pawn]
#if defined Test_H // Checks if the Test_H macro is defined
    #endinput // Stop if the file was included before
#endif
[/pawn]

Everything else looks good.
Do not PM me for support.




Offline Skirmant

  • Made Man
  • ***
  • Posts: 134
    • View Profile
Re: includes?
« Reply #3 on: November 13, 2011, 01:13:01 pm »
Ups. Forgot that pawn uses slightly different rules of macrology ???

Offline Fuzzy168

  • VC:MP Veteran
  • *****
  • Posts: 729
  • Programming since 2011
    • View Profile
Re: includes?
« Reply #4 on: November 13, 2011, 02:05:15 pm »
If i create an include name test.inc its still the same right?
I'm beginning to feel like a Lag God, Lag God

Offline Skirmant

  • Made Man
  • ***
  • Posts: 134
    • View Profile
Re: includes?
« Reply #5 on: November 13, 2011, 02:18:56 pm »
If i create an include name test.inc its still the same right?

Yup. But when loading .inc files use:
[pawn]#include <test>[/pawn]

Offline Fuzzy168

  • VC:MP Veteran
  • *****
  • Posts: 729
  • Programming since 2011
    • View Profile
Re: includes?
« Reply #6 on: November 15, 2011, 01:19:14 pm »
Ok thanks...
I'm beginning to feel like a Lag God, Lag God