Send_var_2 and pointers

Posted By: PrenceOfDarkness

Send_var_2 and pointers - 02/17/08 18:18

I know that send_var_2 can't send pointers and I don't want it to. Is there any way for me to send the variable that the pointer is pointing to?
Posted By: Vadim647

Re: Send_var_2 and pointers - 02/17/08 18:43

Try sending handle(you)
It will simply send object id. Then use ptr_for_handle(myvar).
P.S: You're studying multiplayer, as I see.
Posted By: PrenceOfDarkness

Re: Send_var_2 and pointers - 02/18/08 00:54

variables don't have handles, according to handles in the manual. Anyone else?
Posted By: Tor

Re: Send_var_2 and pointers - 02/18/08 03:05

dereference the pointer.
Posted By: PrenceOfDarkness

Re: Send_var_2 and pointers - 02/18/08 05:13

how?
Posted By: PrenceOfDarkness

Re: Send_var_2 and pointers - 02/19/08 05:40

I did derefrence it, the game crashes...
Posted By: Excessus

Re: Send_var_2 and pointers - 02/19/08 07:57

If I understand you correctly, what you explain is the normal, intended use of send_var_to.

For example, say you have declared global var v. Then you give v a value: v=10;. Then you send it with send_var_to(my, &v). Now it will send the variable that "&v" is pointing to, which is ofcourse v.

&v is a pointer, and likewise you can send any pointer, as long as it points to a global var. For example:
var* p; // var pointer
var v; // var
p = &v; // p points to v
v = 10;
send_var_to(my, p); // no & this time, p is a pointer so you shouldn't take it's address (thats what & does), but just pass its contents which IS a mem addr.
Posted By: PrenceOfDarkness

Re: Send_var_2 and pointers - 02/21/08 18:37

you are completely right! I'm so glad to say that I was doing some stupid stuff with the code I didn't realize.

By any chance do you know the proper way to pass a structs pointer to a function and use it in the function correctly? That's what the crash was. I'm still kind of new to structs I guess.

Code:

typedef struct sZoneMove
{
var zMove;
var zRotate;
} sZoneMove;

sZoneMove sZone1Move1;
sZoneMove* pZoneMove;

function sendVarZone(sZoneMove* test, var zoneNum)
{
send_var_to(tempEnt,test);
}

function someOtherFunction{
pZoneStruct = my.zoneStruct;
pZoneMove = &sZone1Move1;
sendVarZone(pZoneMove.zMove,my.zone);}



Isn't that right?
Posted By: Excessus

Re: Send_var_2 and pointers - 02/21/08 18:44

Whenever you have such a problem, you should be asking yourself: what type is expected here, and what am I actually passing in?

In the case of your sendVarZone function, what type does it expect as first parameter?
What type are you actually passing as a parameter?
Posted By: PrenceOfDarkness

Re: Send_var_2 and pointers - 02/22/08 04:00

Okay I saw that, but it still crashes:

Code:

typedef struct sZoneMove
{
var zMove;
var zRotate;
} sZoneMove;

sZoneMove sZone1Move1;
sZoneMove* pZoneMove;

function sendVarZone(sZoneMove *var, var zoneNum)
{
//the crash happens as soon as sendVarZone is called, nothing ever happens in here
}

....
sendVarZone(pZoneMove,my.zone);



Try it yourself really quick, and you'll see what i mean.
Posted By: Excessus

Re: Send_var_2 and pointers - 02/22/08 07:05

I wouldn't name my variable "var" because that is a reserved keyword. Not sure if that's the problem, though.
© 2024 lite-C Forums