Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,089 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
ent_create(..., ..., function(a, b, c)); possible? #312099
02/23/10 09:42
02/23/10 09:42
Joined: Jul 2009
Posts: 36
S
SomebodyNew Offline OP
Newbie
SomebodyNew  Offline OP
Newbie
S

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:

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 Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
try this instead:
Code:
// 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 wink

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
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 Offline
Senior Member
pararealist  Offline
Senior Member

Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
OR maybe this (untested)
Code:
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
&#9675;pararealist now.
Re: ent_create(..., ..., function(a, b, c)); possible? [Re: pararealist] #312105
02/23/10 10:24
02/23/10 10:24
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline
User
hopfel  Offline
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
Can I barge me in? ^^
Your ideas are not bad, but what can you do, if you want to use the "my" pointer? (Maybe to use IGNORE_ME or so)
The "my" from the entity-function is the same "my" from the function who runs the entity-function, or? So you get problems sometimes. (example: http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=306650&page=2 last post, last three lines :D)

Last edited by hopfel; 02/23/10 10:26.

Hilf mir, dir zu helfen!
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 Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
Originally Posted By: pararealist
OR maybe this (untested)
Code:
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 laugh

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
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 Offline
Senior Member
pararealist  Offline
Senior Member

Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
I take it you mean so?

Code:
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
&#9675;pararealist now.
Re: ent_create(..., ..., function(a, b, c)); possible? [Re: SomebodyNew] #312118
02/23/10 11:34
02/23/10 11:34
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline
User
Gordon  Offline
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
What no one has mentioned is that entity function are not allowed to have parameters. And the manual is currently of no help here. I guess you can think of it this way... the level editor allows you to assign actions to models and other entities. There is no way to assign a parameter to the assigned function in the level editor. ent_create is the script way of placing an entity in the level.

Also your code you first posted the create_scaled_entity(5, 5) is a call to that function not a pointer to that function with parameters. There is no way to code a pointer to a function AND pass parameters to it. This is why my is null as the entity has not been created yet and this function is not associated with the entity only the return value is used as the pointer to the action for this function.

So the bottom line is that entity action functions can not have parameters.


Our new web site:Westmarch Studios
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 Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
Budapest
Totally agree...
Function from the Online Manual

Quote:
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.

Re: ent_create(..., ..., function(a, b, c)); possible? [Re: Aku_Aku] #312492
02/25/10 03:54
02/25/10 03:54
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline
User
Gordon  Offline
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
Good find. I forgot that was there.


Our new web site:Westmarch Studios
Re: ent_create(..., ..., function(a, b, c)); possible? [Re: Gordon] #312493
02/25/10 04:37
02/25/10 04:37
Joined: Apr 2006
Posts: 624
DEEP 13
badapple Offline
User
badapple  Offline
User

Joined: Apr 2006
Posts: 624
DEEP 13
its as simple as this ...

you = ent_create("yourmodel.mdl",vector(0,0,0),NULL);
you.scale_x=your value;
you.scale_y=you.scale_x;
you.scale_z=you.scale_x;

///pass on any peramiters you like///

set(you,PASSABLE | BRIGHT | TRANSLUCENT):
you.alpha=50;

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1