Help understanding basic functions

nobulilo

New member
Greetings!
I'm on the basics of scripting and i'm doing some tests with @cmd on entity file
What i'm trying to do is a little lession to simply write a message on the screen if the attack hits the opponent.
I don't really like to copy and paste scripts, so i've been reading and trying to learning how the scripts works on the engine, but is pretty hard for me doing all by myself.

The problem is, my conditional statement doesn't work and i don't know if is my logic, script code structure (or both) is wrong.

The Script:
Code:
void teste(int t)
{
    void self = getlocalvar ("self");
    if(t == 1) {
    drawstring (10, -60, 1, "Special");
     }
     }

I've already set my character with didhitscript:
Code:
didhitscript  data/scripts/teste.c

name	San
health  80
mp 100
speed	15
type	player
shadow  2
diesound data/chars/san/die.wav
icon	data/chars/san/icon.gif

And the main problem (when i set CMD):
Code:
anim	attack1
	attack	43 21 53 34 5 0 0 0 3 0
	loop	0
	delay	10
	bbox	22 5 20 90
	offset	32 92
	@cmd teste 1
	frame	data/chars/san/a1-00.gif
For what i've been seen, i have to set the parameter like @CMD "script function name" "parameter"
if is a string, i have to put "", and if is int or float i can just put the numbers to set the variable, i am right?

I've already managed to get zoom function work this way but when i create my own function with this parameter and make a statement to activate it through the @cmd, the OpenBorLog shows  "cannot find the function":

Code:
Script compile error: can't find function 'teste'

Script compile error in 'San': teste line 9, column 12

I've managed to get the script work without activating @cmd at the first time with this:
Code:
void main()
{
    void self = getlocalvar ("self");
    float z = getentityproperty(self, "z");
    void ani = getentityproperty(self, "animationid");
    if (ani == openborconstant("ANI_FREESPECIAL")) {
    drawstring (10, z-60, 1, "Special");
     }
    }

I Know is not too optimal, but i'm just learning and trying to make simple lessions to get a little bit complex later.
So, how can i make this function work activating this through @CMD ?!

I'll put my mod on dreamcast so i'm using the Build 3984 (I've tried everything on most recent builds but i'm getting the same issue)
I really appreciate the help guys! I've been learning a lot here.  ;D
 
nobulilo,

Welcome to Chronocrash!

At first glance I don't see any issues with your code. The main problem is you don't have the function defined in correct script file. @cmd tags call functions from the model's animation event script. The name is somewhat misleading, it runs every time an animation frame changes.

Code:
animationscript <path to script>

Put the function in that script file, and then you can call it. Later you'll want to look into #include and #import to efficiently reuse code, but don't worry about that just yet. Also note - animationscript is somewhat unique in that you do not and can not put a main() in it.

DC
 
Damon Caskey

Thank you so Much, mr. Damon!!
I've managed to call the function with @cmd on the entity now
i've forgot to put animation script on the entity like you've said.

Just to clarify:
-The @cmd works only for animation scripts
- If i want to get more results from other statements (Like, attack confirm, zoom screen and etc) i have to import other scripts into that animation script

Thank you so much!
;D
 
nobulilo,

The @cmd works only for animation scripts
That is true. @cmd is just a way to run a function from the text file on a frame. You can use more than one @cmd per frame by the way, and of course you can also call OpenBOR defined functions as well.

If i want to get more results from other statements (Like, attack confirm, zoom screen and etc) i have to import other scripts into that animation script

It depends entirely on what you want to do. Animation scripts are indeed powerful and necessary, but many things are better suited for other event scripts. One example might be playing a voice sound when the character gets hit. You could do that putting a @cmd in all the pain animations, but it's much easier and more optimal with the takedamage event. Learning which event to use and how to combine them is one of the more important skills you'll need for script work.

Here is a guide I wrote that might help you along the way.

DC
 
I'll be sure to check and study, it will be extremely useful to me.
You've helped me a lot, i made a lot of scripts just for fun and practice here, it seems a little bit easier now  ;D

Thanks a lot man!
 
Back
Top Bottom