how to use other .c files

Posted By: Dega

how to use other .c files - 11/18/13 20:44

So I am trying to write several scripts and I need Encounters.c to be used in Main.c but it won't recognize the functions from it. Am I supposed to only use one script for everything or can I do this??? Thanks
Posted By: Quad

Re: how to use other .c files - 11/18/13 20:45

#include "Encounters.c"
Posted By: Dega

Re: how to use other .c files - 11/18/13 20:48

is there anything else I should know about doing this? I tried that and it won't work.
Posted By: Dega

Re: how to use other .c files - 11/18/13 21:11

Okay I got it to work but now every time Encounters.c does anything in the game it gets an error saying "Error:E1513" and says it crashed. Can you tell me anything about that?
Posted By: Quad

Re: how to use other .c files - 11/18/13 21:14

There are probably like a hundred things you need to know about that. "it won't work" simply means nothing, there can be truck load of reasons for that and i can't guess which one. What error you actually get?

For starters:
  • Included file needs to be on the same directory as your main file, otherwise you need to use relative path. like #include "scripts/someFile.c"
  • You should include your file at the beginning of your main.c, not in the middle of some code.
  • You need to make sure you do not include same files twice or take proper measures to not break anything in case you need to do that.
  • In lite-c/acknex environment, if you do not have any #includes default.c and acknex.h are automatically included for you. acknex.h is mandatory for engine to work. So if you have any self-included files you need to include acknex.h manually probably before ALL of your custom includes.
Posted By: Quad

Re: how to use other .c files - 11/18/13 21:15

For your second message you need to post your project and/or script files.
Posted By: Dega

Re: how to use other .c files - 11/18/13 21:27

Okay I got the code working without the error but I had to erase all the code in the Encounter.c function. It seems I need to learn how to make code work in other files. Any tutorials with included .c files I could take a look at?
Posted By: Uhrwerk

Re: how to use other .c files - 11/18/13 22:30

You really don't need a tutorial for that. It's easy as pie. Just imagine that when you write " include "sample.c" this will place the contents of sample.c exactly where you have the include.
Posted By: Dega

Re: how to use other .c files - 11/19/13 16:39

For some reason when I put this in a void it gets an error e1513 which says I am referencing something that isn't there.

Code:
void goto_encounter() {

//put player in the encounter room
player.x = 0;
player.y = 0;
player.z = -300;

}

Posted By: Uhrwerk

Re: how to use other .c files - 11/19/13 19:34

Please describe your problem in more detail. What do you mean by "when I put this in a void"? The following code compiles perfectly fine:
Code:
#include <acknex.h>

void goto_encounter()
{
	//put player in the encounter room
	player.x = 0;
	player.y = 0;
	player.z = -300;
}

Posted By: Dega

Re: how to use other .c files - 11/19/13 20:36

Basically when I use it, I get a error at runtime. It appears I am referencing something that doesn't exist. I think I am figuring it out though. I will let you know if I do.
Posted By: Anonymous

Re: how to use other .c files - 11/20/13 03:11

Lol in your player action did you set player?

Code:
action player_act()
{
player = me;
.....
}



if so then there should be no problem.
Posted By: wrekWIRED

Re: how to use other .c files - 11/21/13 12:46

80% of the time when having different files for my codes I tend to miss the proper pointer which cause the error. There are also times where in pointer player isn't recognize right away after pointing your entity as the player and calling a function that use player pointer. It would help to wait until player pointer exist before executing your code like.

Code:
void goto_encounter()
{
   while(!player){wait(1);}
   player.x = 0;
   player.y = 0;
   player.z = -300;
}

© 2024 lite-C Forums