0 registered members (),
1,459
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
ent_create(..., ..., function(a, b, c)); possible?
#312099
02/23/10 09:42
02/23/10 09:42
|
Joined: Jul 2009
Posts: 36
SomebodyNew
OP
Newbie
|
OP
Newbie
Joined: Jul 2009
Posts: 36
|
Hello everybody, the function ent_create(STRING* filename, VECTOR* position, function); is used to create an entity and immediately assign a function to that newly created entity. I would like to pass over values to the function that is assigned to the new entity. To do this I tried the following code:
// The basic includes
#include <acknex.h>
#include <default.c>
// List of functions
function create_scaled_entity(X_Scale, Y_Scale);
function main();
function create_scaled_entity(X_Scale, Y_Scale)
{
my.scale_x = X_Scale;
my.scale_y = Y_Scale;
}
function main()
{
level_load(NULL);
camera.tilt= -90;
camera.z = 3000;
ent_create("Test.mdl", nullvector, create_scaled_entity(5, 5));
}
This is pretty straight forward. The "main" function creates an entity via ent_create and assigns the function "create_scaled_entity" to this newly created entity. This works until I try to pass over parameters to the new entity in the same line that creates it. The engine crashes and returns an E1513 "Crash in ..." (mostly it is an empty-pointer-error). Am I doing something wrong or is this not possible? If so, is there a workaround? I don't really understand why this returns a pointer-error. Thank you for taking a look at this. Have a good start in the day.
|
|
|
Re: ent_create(..., ..., function(a, b, c)); possible?
[Re: SomebodyNew]
#312100
02/23/10 09:45
02/23/10 09:45
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
try this instead:
// The basic includes
#include <acknex.h>
#include <default.c>
// List of functions
function create_scaled_entity(ENTITY* Ent, var X_Scale, var Y_Scale);
function main();
function create_scaled_entity(ENTITY* Ent, var X_Scale, var Y_Scale)
{
Ent.scale_x = X_Scale;
Ent.scale_y = Y_Scale;
}
function main()
{
level_load(NULL);
camera.tilt= -90;
camera.z = 3000;
ENTITY* tempEnt = ent_create("Test.mdl", nullvector, NULL);
create_scaled_entity(tempEnt, 5, 5)
}
Untested, but you get the idea regards,
|
|
|
Re: ent_create(..., ..., function(a, b, c)); possible?
[Re: Helghast]
#312102
02/23/10 10:07
02/23/10 10:07
|
Joined: Dec 2006
Posts: 434 UK,Terra, SolarSystem, Milky W...
pararealist
Senior Member
|
Senior Member
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
|
OR maybe this (untested)
ENTITY* create_scaled_entity( var Scale, STRING* model)
{
ENTITY* tempEnt = ent_create(model, nullvector, NULL);
if(tempEnt != NULL)
{
//scale all axis the same
tempEnt.scale_x = Scale;
tempEnt.scale_y = Scale;
tempEnt.scale_z = Scale;
//
return tempEnt;
}
return NULL;
}
A8.3x Commercial, AcknexWrapper and VS 2010 Express ○pararealist now.
|
|
|
Re: ent_create(..., ..., function(a, b, c)); possible?
[Re: pararealist]
#312107
02/23/10 10:35
02/23/10 10:35
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
OR maybe this (untested)
ENTITY* create_scaled_entity( var Scale, STRING* model)
{
ENTITY* tempEnt = ent_create(model, nullvector, NULL);
if(tempEnt != NULL)
{
//scale all axis the same
tempEnt.scale_x = Scale;
tempEnt.scale_y = Scale;
tempEnt.scale_z = Scale;
//
return tempEnt;
}
return NULL;
}
Doesnt make alot of sense to return NULL there, return the entity instead then, otherwise you might be right, this would be a better function regards,
|
|
|
Re: ent_create(..., ..., function(a, b, c)); possible?
[Re: Helghast]
#312111
02/23/10 10:53
02/23/10 10:53
|
Joined: Dec 2006
Posts: 434 UK,Terra, SolarSystem, Milky W...
pararealist
Senior Member
|
Senior Member
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
|
I take it you mean so?
ENTITY* create_scaled_entity( var Scale, STRING* model)
{
ENTITY* tempEnt = ent_create(model, nullvector, NULL);
if(tempEnt != NULL)
{
//scale all axis the same
tempEnt.scale_x = Scale;
tempEnt.scale_y = Scale;
tempEnt.scale_z = Scale;
//
}
return tempEnt;
}
A8.3x Commercial, AcknexWrapper and VS 2010 Express ○pararealist now.
|
|
|
Re: ent_create(..., ..., function(a, b, c)); possible?
[Re: Gordon]
#312232
02/23/10 19:55
02/23/10 19:55
|
Joined: Sep 2009
Posts: 993 Budapest
Aku_Aku
User
|
User
Joined: Sep 2009
Posts: 993
Budapest
|
Totally agree... Function from the Online Manual Quote: Actions are another special kind of functions. They don't have parameters and don't return a value, but will appear in the action pop-up list in WED's entity property panel. So actions can be assigned to entities through WED, and are automatically executed after level loading. Action names are limited to 20 characters. Besides that, there is no difference between functions and actions. This is our usual example for an entity action, which consists of just three instructions, and lets the entity rotate So actions can not have parameters.
|
|
|
|