Hi Plombo, I was going to contact you about your trick.
If you try my game (http://gamejolt.com/games/avengers-united-battle-force/14591) you will notice somethings. It will be a long reply so sorry for that (and for my crap english):
1- I have a file with codes from other people (DC, BB, uTunnels, WD, etc) and a file called
ilu.h, where I put all my codes. This helps me better tracking of what I do.
The animationscript file is called
grabscript.c where I was using
Code:
#include "data/scripts/ilu.h"
#import "data/scripts/library/ani0020.h"
#import "data/scripts/randsound.c"
#import "data/scripts/grabscript_actual.c"
The 1st is my library, the 2nd is a DC library (works ok), the 3rd has some random codes (talk more about this later) and the actual main animationscript file -
grabscript_actual.c. Notice that I use INCLUDE and not IMPORT (talk more about this later too).
in the
grabscript_actual.c I was calling those files:
Code:
#include "data/scripts/ilu.h"
#import "data/scripts/library/ani0020.h"
I know I was stupid for calling the same file two times (I was testing the import/include and I forgot to remove). If I tried to
IMPORT ilu.h, the log says it can't find a script inside
grascript_actual.c (and I dont understand why.) and everytime I call a function from randsound, it says It can't find that script too. If I change to
INLCUDE, it works - but It won't use that trick and will consume more RAM that it should (around 140MB).
The randsound.c has simply random sound scripts like this, nothing too fancy:
Code:
void randSound0(char s1,char s2)
{
int r = rand()%100;
char sound;
if (r<=0)
{
sound=s1;
}else{
sound=s2;
}
playSound("data/"+sound);
}
void playSound(void file)
{
if(!file||file==""){return;}else{}
int sfx=loadsample(file);
playsample(sfx, 0, openborvariant("effectvol"), openborvariant("effectvol"), 100, 0);
}
2- So I had to stick with INCLUDE. But right after I use your trick, some rand() based functions started to act very strangely, suffering a lot from the First Frame Bug.
I can give an example (you will need to download my game to see it):
- Pick Hulk, go to any stage and press the SPECIAL button. You will see some effects ("crack", on the floor and "stompfx" which is an impact effect). "stompfx" calls some random debris (debris1, debris2, debris3 and debris4) on the screen. now pay attention to those debris - you will see that some are called from here Hulk is and some are called...from the edge of the screen.
Here is the stompfx file:
name stompfx
type none
shadow 0
Antigravity 100
lifespan 0.24
palette data/chars/misc/stompfx/pal.png
animationscript data/scripts/grabscript.c
load debris1
load debris2
load debris3
load debris4
anim idle
loop 0
delay 6
offset 80 45
sound data/sounds/bigland.wav
quakeframe 0 2 20
@cmd spawnRandEnt "debris1" "debris2" "debris3" "debris4" 0 0 0
@cmd spawnRandEnt "debris1" "debris2" "debris3" "debris4" 0 0 0
frame data/chars/misc/stompfx/stomp_4771-0.png
offset 88 57
@cmd spawnRandEnt "debris1" "debris2" "debris3" "debris4" 0 0 0
@cmd spawnRandEnt "debris1" "debris2" "debris3" "debris4" 0 0 0
frame data/chars/misc/stompfx/stomp_4771-1.png
offset 94 56
frame data/chars/misc/stompfx/stomp_4771-2.png
offset 102 59
frame data/chars/misc/stompfx/stomp_4771-3.png
Pay attention that I am calling my custom function on the first frame, using this code
Code:
void spawnRandEnt(void vName1,void vName2,void vName3,void vName4,int vx, int vy, int vz )
// Spawn Random entities at random places
// 03/02/2014 - Douglas Baldan - O Ilusionista
{
// int Xr = rand()%vx; // Random X pos
// int Yr = rand()%vy; // Random Y pos
// int Zr = rand()%vz; // Random Z pos
int Sr = rand()%4+4;
if(Sr == 0){
spawn000(vName1,vx,vy,vz);
}
else if(Sr == 1){
spawn000(vName2,vx,vy,vz);
}
else if(Sr == 2){
spawn000(vName3,vx,vy,vz);
}
else {
spawn000(vName4,vx,vy,vz);
}
}
"spawn000" is just DC's spawn01 function without direction.
How I solved this? I just changed the code to the second frame...and it works. This wasn't needed before I changed to the IMPORT trick.
Right now, I am using a combined file (which has "grabscript_actual" + "ilu.h") to reduce the RAM usage, using IMPORT
Code:
#import "data/scripts/library/ani0020.h"
#import "data/scripts/grabscript_complete.c"
And it works. But I still would need my
ilu.h file splited into a separated file. If I remove my code from that file and use
Code:
#import "data/scripts/ilu.h"
The engine returns the error:
Script compile error: can't find function 'spawn01'
Script compile error in 'data/scripts/ilu.h': spawn01 line 784, column 0
Script error: failed to import 'data/scripts/ilu.h': failed to compile
Script error: failed to import 'data/scripts/grabscript_complete.c': failed to compile
Which doesn't makes sense, since "spawn01" function is inside the
grabscript_complete.c file...
Any help would be good.
PS: sorry if I made any noob mistake. I am trying to learn so if I did something wrong, please point me to the best solution. I am totally open to feedback.