Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, chsmac85, NeoDumont, dr_panther, TedMar), 1,086 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
You Pointer still working in Lite-C? #225558
09/05/08 04:40
09/05/08 04:40
Joined: Apr 2004
Posts: 516
USA
Trooper119 Offline OP
User
Trooper119  Offline OP
User

Joined: Apr 2004
Posts: 516
USA
I'm using free Light-C and have come across either a really easy or really odd problem depending on what I'm doing wrong. I have the following code called when a projectile hits the character. I get an "Error E1515: Invalid arguments in modelHit" when the program first runs. When I remove the 'you' instructions (and replace them with 'my's) the error goes away. I can plenty of code and examples to show you guys if you want, but I'm hoping this is the source of the problem.

Code:
function modelHit()
{
	switch(event_type)
	{
		case EVENT_IMPACT:
			addLine("Characters are colliding, Oh my!");
			double modifierForUp = (3/4);
			double modifierForDown = (1/4);
			int launchAngle = 30;
			
			if(you.push == 2)		//A projectile has hit the character
			{
				//Check velocity of projectile, character will impact in the same direction regardless of where you hit the projectile
				//my.skill1 = damage, my.skill2 = orientation
				if(you.velX <= 0)
				{	//launch with a force 30 degrees into the air
					my.velX = -1 + you.damage * my.health * cos(launchAngle) * -1;
					my.velZ = 1 + you.damage * my.health * sin(launchAngle);
				}
				else  
				{	//launch with a force 30 degrees into the air
					my.velX = 1 + you.damage * my.health * cos(launchAngle);
					my.velZ = 1 + you.damage * my.health * sin(launchAngle);
				}  
				my.health += you.damage;

				you.state = dead;
				//previously had the following code
                                //wait(1);
                                //ent_remove(you);  //Now works just fine with
                    //these too remove, commented it out here so others could see
				return;
			}
       }
}


Code above works just fine now, previously had a wait(1); then a remove(you); statement, removed and handled elsewhere in the code did the trick.

Last edited by Trooper119; 09/05/08 13:52.

A clever person solves a problem.
A wise person avoids it.
--Einstein

Currently Codeing: Free Lite-C
Re: You Pointer still working in Lite-C? [Re: Trooper119] #225614
09/05/08 10:10
09/05/08 10:10
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Im not big on events, but I feel the problem is somewhere here
Code:
   you.state = dead;
   wait(1);      //Let the object know it's dead and exit the function
   ent_remove(you);
If the YOU object has an action that makes it ent_remove itself on "dead" state, then it has time to do so during the wait(1).
So now the YOU pointer is empty in this function, and errors out on the ent_remove(you); line.

If the YOU entity does self-remove, then I suggest ditching the ent_remove(you), assuming the YOU can be trusted to 'die' properly.
Otherwise ditch the you.state and wait lines so it 'dies' here.

Let us know how it goes...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: You Pointer still working in Lite-C? [Re: EvilSOB] #225635
09/05/08 13:50
09/05/08 13:50
Joined: Apr 2004
Posts: 516
USA
Trooper119 Offline OP
User
Trooper119  Offline OP
User

Joined: Apr 2004
Posts: 516
USA
I changed my code above according to your suggestion, thanks a lot, I forgot about the wait() changing pointers, stupid mistake I should have seen.

I changed the way I handled death for my characters and projectiles and it all works fine now, thanks a bunch.


A clever person solves a problem.
A wise person avoids it.
--Einstein

Currently Codeing: Free Lite-C
Re: You Pointer still working in Lite-C? [Re: Trooper119] #225636
09/05/08 13:57
09/05/08 13:57
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
No problem, glad I could help. wink

blush Even though I never 'meant' to suggest the YOU pointer changing just due to the wait.
I always forget about that too. Note to self Remember wait(?) means YOU cant be trusted anymore.
I actually meant that the Action the YOU entity was running may have been
ent_removing itself and so YOU has nothing to point at anymore.

You saw an answer I didnt intend to give. Well done.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: You Pointer still working in Lite-C? [Re: EvilSOB] #225689
09/05/08 19:08
09/05/08 19:08
Joined: Apr 2004
Posts: 516
USA
Trooper119 Offline OP
User
Trooper119  Offline OP
User

Joined: Apr 2004
Posts: 516
USA
rofl, that's great, no need to be so humble though. You helped me realize what I did wrong, now off to errors A-Q.

Good luck everyone.


A clever person solves a problem.
A wise person avoids it.
--Einstein

Currently Codeing: Free Lite-C

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