Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, Grant, Neb), 908 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Attaching Entitys to each other #203368
04/21/08 16:47
04/21/08 16:47
Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
Roxas Offline OP
Member
Roxas  Offline OP
Member

Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
Hey guys.

I just wanted to attach a Sword to a Model's hand.
I tried this with vec_for_vertex, but everytime, when I save the position of the Vertex of the charakter, to a vector like temp or something, it says "empty pointer" ôo.

 Code:
action player_move()
{
        VECTOR* temp;
	charakter = me;
	set (charakter, SHADOW);
	charakter.z_offset = 28;
	while(1)
	{
		handle_gravity();
		camera_handle();
		movement_handle();
		animation_handle();
		tt_npc_handle();
		wait(1);
	}

}


that's what my player action looks like at the moment.
when I add:

vec_for_vertex(temp, charakter, 1178);
ent_create("sword.mdl", temp, NULL);

just before the while loop begins, I get the error that there is an empty pointer in tt_npc_handle.

I just wanted to test so far, if the sword model will be created near the vertex , when I run the engine. but I just get the error..
I wanted to change the "NULL" to an action that handles with the postiion of the sword, during moving of the charakter etc.

but I'm not able to solve the problem with the error..
I even don't know why he indicates an error in the tt_npc_handle thing, hasn't much to do, with the vec_for_vertex, or does this command erase the pointers oO?

here's the tt_npc_handle code

 Code:
//NPC TextBox Handling 
function tt_npc_handle() 
{
	if(txtbox == aus && talking == aus) 
	{
		on_e = scan_npcs;
	} 
	if(txtbox == an && talking == an)
	{
		on_e = NULL;
	}
	if(txtbox == an && txtnext == an)
	{
		on_e = nextstring;
	}
	if(txtbox == an && txtend == an)
	{
		on_e = txtclose;
	}
}


well I don't even know what to do and why the empty pointer error appears.
hope you can help me with that ..

greets

Re: Attaching Entitys to each other [Re: Roxas] #203382
04/21/08 18:26
04/21/08 18:26
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
 Code:
action player_move()
{
        VECTOR* temp;
	charakter = me;
With VECTOR* temp you have defined a pointer to a vector. This pointer is pointing to a random memory area on your pc. Before you can use such a pointer to a vector you have to allocate memory for the vector with malloc and assign the address to temp.
 Code:
VECTOR* temp = (VECTOR*)malloc(sizeof(VECTOR));
/*don't forget to free the memory later on. Otherwise you'll create a memory leak. */
free(temp);
/* Always a good idea after freeing something. */
temp = NULL;
The other possibility is to defeine temp like this:
 Code:
/* Now the vector is automatically allocated. */
VECTOR temp;
/* Don't forget the "&" because vec_for_vertex expects a pointer. */
vec_for_vertex(&temp, charakter, 1178);


The difference between the methods is, where the memory is allocated. In the first example it's created on the heap. In the second one temp will be allocated on the stack.

EDIT: Error messages are a little confusing in lite-c sometimes. If a crash is reported in a certain function it's either in that exact function or any of its sunfunctions.


Always learn from history, to be sure you make the same mistakes again...
Re: Attaching Entitys to each other [Re: Roxas] #203395
04/21/08 19:44
04/21/08 19:44
Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
Roxas Offline OP
Member
Roxas  Offline OP
Member

Joined: Apr 2008
Posts: 144
Germany | Niedersachsen (Lower...
Thank You Uhrwerk for your help again =O
you really made my day!
It works now.

Now I have to figure out how to code, that the sword will stay in the position of the charakter and so on, but I think I'm able to somehow to get that to work. Might be a little tricky but that's the only way I can learn something I guess, right?

So thank you for your help^^.
I'll post in this thread again if more problems will come up. But I hope I can solve the rest by myself.

Greets ~


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