Short unsigned problem

Posted By: EpsiloN

Short unsigned problem - 12/23/15 09:10

Code:
rnd = random(400) - 200;
terrainStruct.x = rnd;


The problem is:
rnd = -59;
terrainStruct.x = 64xxx; (or 65xxx?)

rnd is a var, terrainStruct.x is a "short" (also tried "signed short"), but the short overflows (right term?)...

Anyone got any ideas? laugh


EDIT:
I just noticed that the manual shows short range as "0 to 65535", I guess its always unsigned.
I'll try to unsign my pos (subtracting) and store it, then sign upon retrieval, but I've got to find the exact middle value, I guess...
Posted By: MasterQ32

Re: Short unsigned problem - 12/23/15 12:32

lite-c does not now unsigned afaik but when shorts are always unsigned: WTF? grin
Posted By: EpsiloN

Re: Short unsigned problem - 12/23/15 12:57

I made a shortcut.
Code:
function unsign_short(x) { return x + 32768; }
function sign_short( short x ) { return x - 32768; }



Here's the problem grin
Manual says:
Quote:

short - 2 bytes - 0 to 65535

And, it also says:
Quote:
Signed or unsigned variables

In lite-C, var, float, double, long and int variables are always signed, and pointers, char and short are always unsigned, according to the normal way they are used. The signed and unsigned variable modifiers are accepted, but have no effect.
Posted By: MasterQ32

Re: Short unsigned problem - 12/23/15 13:50

Okay, this is quite weird grin
Posted By: EpsiloN

Re: Short unsigned problem - 12/23/15 14:11

The Weirdness doesn't stop here grin

All of the sudden, this:
Code:
ENTITY* playerEnt = ent_createlocal("bot2.mdl" , posVector , playerEntity );


doesn't attach playerEntity() function to the model!!!

If I cheat it, it works:
Code:
ENTITY* playerEnt = ent_createlocal("bot2.mdl" , posVector , NULL );
playerEntity( playerEnt );


Talk about bugs tongue
I'm feeling desperate now...
Posted By: txesmi

Re: Short unsigned problem - 12/23/15 18:56

Did you set any value to 'dplay_localfunction'?
Posted By: EpsiloN

Re: Short unsigned problem - 12/23/15 19:42

No. It should default to 0, meaning actions only on server (but for global entities, not ent_createlocal)

I just dropped my MP project because of a bug(?) with localfunction, I guess.

The manual states, that functions should run on server only, and I based my whole MP Tutorial on that part... I even checked the value (it was 0!)
After I developed most of the gameplay, I realized I was shooting two bullets at the same time from one gun. After further checking (I disabled all client shooting init) it was still shooting one bullet, and the bullet even got the local collision of the server's bullet. I mean, an ent_createlocal-ly created bullet, that SHOULD NOT exist on the server was hitting an entity that existed ONLY on the server grin Talk about bugs...

I'm now fighting to make a full system out of ent_createlocals and all structs. I'll try to avoid using any of the built in stuff, except send_data_to laugh

I even made a custom Collision system for this project grin hahah... But, at least I'm not rendering the screen by myself, yet tongue

Anyway, I'm gonna check the createlocal again, if its attaching a function now, but I guess there is something wrong with how the ent_create and ent_createlocal works with Multiplayer...

EDIT*
I don't know if this sounds stupid, but is it possible, with all my sys_malloc functions, that I'm assigning something to dplay_localfunction by accident, by expanding my struct pointer more than it really is in memory? Just a thought...
© 2024 lite-C Forums