Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
5 registered members (AbrahamR, wdlmaster, 7th_zorro, dr_panther, 1 invisible), 764 guests, and 5 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
Problems with pointers [new title] #335723
07/30/10 11:09
07/30/10 11:09
Joined: Jul 2010
Posts: 127
Germany, Herford
Ditje Offline OP
Member
Ditje  Offline OP
Member

Joined: Jul 2010
Posts: 127
Germany, Herford
When I try to shoot my enemies, I use ent_remove(you). But if I hit the target, I (players ship) got removed not the hidden target grin

Code:
function move_bomb() 
{
	c_setminmax(me); // bounding box setzten
	my.STATE = 1;
	my.pan = your.pan;
	my.tilt = your.tilt;
	my.roll = your.roll;
	
	while(1)
	{
		// Bombe flieg
		if (my.STATE == 1) 
		{
			c_move(me, vector(0, 50 * time_step, 0), vector(0, 0, 0), IGNORE_YOU);
			if(my.y >= 980 || my.z >= 580) 
        	{ // levelende erreicht?
        		my.STATE = 2;
        	}
        	if (HIT_TARGET) 
        	{
				//ent_create("explosion+4.bmp",vector(my.x,my.y,my.z+20),NULL); // particle effect planned
        		ent_remove(you);
        		my.STATE = 2;
        	}
		}
		// Bombe verschwinde
		if (my.STATE == 2) 
		{
        	ent_remove(me);
        	
        	bomb_anzahl --;
        	return; // !!! prevents further access to removed entity
			
		}
		wait(1);
	}
}



an this is the player action, from where function move_bomb is called:

Code:
action spieler_aktion()
{
	spieler = my;
	my.STATE = 1;
	
	while(1)
	{
		// auf und ab drehen
                ...
                 code for ship controll
		...



		// Schiessen - code for fireing
		if (my.STATE == 1) // kein Schuss
	   {
			if(mouse_left) my.STATE = 2;
		}
		if(my.STATE == 2) // Schuss  
		{
			if(last_bomb_x == 15) last_bomb_x = -15;
			else last_bomb_x = 15;
			if(bomb_anzahl < 4)
			{
				ent_create("bomb.mdl",vector(my.x+last_bomb_x,my.y+10,my.z),move_bomb);
				bomb_anzahl ++;
			}
			my.STATE = 3;
		}
		if (my.STATE == 3)
		{
			if (!mouse_left) my.STATE = 1;
		}
		wait(1);
	}
}



Cheers

Ditje

Last edited by Ditje; 08/02/10 14:39.
Re: who is you? - :-D funny effect [Re: Ditje] #335724
07/30/10 11:16
07/30/10 11:16
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
does this help?

"hit.entity ENTITY* pointer, or NULL when a level surface was hit."

http://www.conitec.net/beta/hit.htm

Re: who is you? - :-D funny effect [Re: Pappenheimer] #335753
07/30/10 13:15
07/30/10 13:15
Joined: Jul 2010
Posts: 127
Germany, Herford
Ditje Offline OP
Member
Ditje  Offline OP
Member

Joined: Jul 2010
Posts: 127
Germany, Herford
May be - I don`t know how to use "hit" Do I have to check if "bomb" hits or if enemy got "hit"?

1.) where do I have to use the function in my shooting-function or enemy-function?

2.) how do I get the pointer?

Thx Ditje

Re: who is you? - :-D funny effect [Re: Ditje] #335757
07/30/10 13:32
07/30/10 13:32
Joined: Aug 2008
Posts: 482
B
bart_the_13th Offline
Senior Member
bart_the_13th  Offline
Senior Member
B

Joined: Aug 2008
Posts: 482
try to avoid using ent_remove(me) inside a loop since it could mess your code and put it at the end of your code.

Try this code to replace your move bomb
Code:
function move_bomb() 
{
	c_setminmax(me); // bounding box setzten
	my.STATE = 1;
	my.pan = your.pan;
	my.tilt = your.tilt;
	my.roll = your.roll;
	
	while(my.STATE==1)
	{
		// Bombe flieg
		c_move(me, vector(0, 50 * time_step, 0), vector(0, 0, 0), IGNORE_YOU);
		if(my.y >= 980 || my.z >= 580) 
        	{ // levelende erreicht?
        		my.STATE = 2;
        	}
        	if (HIT_TARGET || my.y >= 980 || my.z >= 580) 
        	{
				//ent_create("explosion+4.bmp",vector(my.x,my.y,my.z+20),NULL); // particle effect planned
        		my.STATE = 2;
                        if(HIT TARGET)
                        {
                        //do something here to the HIT_TARGET
                        }
        	}
		wait(1);
        }
        ent_remove(me);
}



Re: who is you? - :-D funny effect [Re: bart_the_13th] #335766
07/30/10 13:41
07/30/10 13:41
Joined: Jul 2010
Posts: 127
Germany, Herford
Ditje Offline OP
Member
Ditje  Offline OP
Member

Joined: Jul 2010
Posts: 127
Germany, Herford
Ah looks nice. Thank you. I will try it on monday - SED is already closed. I have to prepare me for Open Air laugh

Cheers

Ditje

Re: Problems with pointers [new title] [Re: Ditje] #336226
08/02/10 14:38
08/02/10 14:38
Joined: Jul 2010
Posts: 127
Germany, Herford
Ditje Offline OP
Member
Ditje  Offline OP
Member

Joined: Jul 2010
Posts: 127
Germany, Herford
Hi

I figured out a little bit how to use pointers. But not everything. Below you find my code - not needed is deleted.

1.) I want to call a function instead of only remove enemy and have no idea how to do it.

2.) After I have shoot some enemies I get 2 error messages. Invalid argument and SYS crash in move_bomb(). I can "play" further. After some time I get Invalid argument at every hit.

May be calling the function is already the solution. But I don`t know the reason for errors.

Cheers

Ditje

Code:
// enemy functions ///////////////////////////////////////
function start_level_type1()
{
...
   // a loop creates 40+n enemies
   enemy = ent_create("bee1.mdl", vector(50, 1000, 500), start_bee_wave1);
...
}

function start_bee_wave1
{
   // moves the enemies until until they reach their temporary position
}

function attack_player
{
   // not done yet - get called 
   // if a all enemies reached final posion
   // or if an enemy got killed
   // of if an enemy got back from attack to temporary postion
}


// bomb functions /////////////////////////////////////////
function move_bomb() 
{
   ...
   if (HIT_TARGET) 
   {
      snd_play(snd_explode,100,0);
      punkte_spieler += 30;
      ///!!!!!!! Here is my problem !!!!!!!!!! ///////////
      ent_remove(enemy);
      my.STATE = 3;
   }
   ...
}


// player action (added in WED) ///////////////////////////
action spieler_aktion()
{
...
   bomb = ent_create("bomb.mdl",vector(my.x+last_bomb_x,my.y+10,my.z),move_bomb);
...
}



Last edited by Ditje; 08/02/10 14:40.
Re: Problems with pointers [new title] [Re: Ditje] #336238
08/02/10 15:53
08/02/10 15:53
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Hi, using pointers in Lite-C is pretty easy. I assume you have worked through the Lite-C workshop.

1) You can call a function from anywhere. All you have to do is create a new function with the code you want to call, give it a useful name and call it.
Code:
void main()
{
beep(); // make the engine 'beep'.
}


The above code using a seperate function...
Code:
void CallBeep()
{
beep();
}

void main()
{
CallBeep();
}


This is a useless example but shows you that you can break any code in various functions. This is called modular programming.

2) The reason the 'ent_remove(enemy);' call crashes is because the 'enemy' pointer is NULL. Removing a NULL pointer results in a crash. Make sure that 'enemy' isn't being removed already.

Re: Problems with pointers [new title] [Re: DJBMASTER] #336240
08/02/10 16:23
08/02/10 16:23
Joined: Jul 2010
Posts: 127
Germany, Herford
Ditje Offline OP
Member
Ditje  Offline OP
Member

Joined: Jul 2010
Posts: 127
Germany, Herford
Simply calling a function is not my problem. But in this case. I have a HIT_TARGET event and my function adresses the hit target, how do I call the function and give the hit ENTITY as parameter?

I noticed already, that my problem must already earlier, when I creat my enemies:

enemy = ent_create("bee1.mdl", vector(-100, 800, 400), start_bee_wave5);

This is done in a loop - so "enemy" got overwritten every time and keeps the value of the last loop. That`s the reason why I get the errormessage only sometimes. Can I create ENTITIES in an array like this?

enemy[i] = ent_create("bee1.mdl", vector(-100, 800, 400), start_bee_wave5);

Re: Problems with pointers [new title] [Re: Ditje] #336243
08/02/10 16:37
08/02/10 16:37
Joined: Nov 2009
Posts: 89
Germany, NRW
T
TrackingKeks Offline
Junior Member
TrackingKeks  Offline
Junior Member
T

Joined: Nov 2009
Posts: 89
Germany, NRW
Yes^^


Gamestudio: A7.82 Commercial/A8 Commercial
System specs (Laptop):
Windows 7 64bit
DirectX v10.1
Intel Core i7-720QM CPU @ 1,60 GHz
4GB DDR2 Ram
NVIDIA GeForce GT 230M (1024MB)
Re: Problems with pointers [new title] [Re: TrackingKeks] #336267
08/02/10 17:36
08/02/10 17:36
Joined: Jul 2010
Posts: 127
Germany, Herford
Ditje Offline OP
Member
Ditje  Offline OP
Member

Joined: Jul 2010
Posts: 127
Germany, Herford
hmmm in my case sadly not. Error

Cannot convert POINTR to 'struct ENTITY'

Edit again: There are 2 problems this is getting the hit TARGET but there is an additional problem decribed in the following post
laugh sorry for to much posts

I still suppose, that I haven`t found the right (english) description for my problem. This must be absolute basic laugh

- I have a variable ammount of enemies created by ent_create
- I have a variable ammount of bombs

Any bomb can hit any enemy. If (HIT_TARGET), there are a lot of things to do:

- remove bomb
- remove enemy
- count up score
- play sound
- particle effect

So if I create functions which are called by if(HIT_TARGET) the functions have to know which ENTITIES (bomb OR enemy) depend on.

Now I check (HIT_TARGET) on my bombs and try to ent_remove(enemy). functionname(enemy) should work, to. But it doesn`t. I am sure solution with an array of enemies is not the right solution.

I supposed that I can call the TARGET by "you". But doesn`t work. (see above: players ENTITY is "you"). Very weird, because it got not HIT. So how do I get the information which enemy is HIT?


German:
Das HIT_TARGET treibt mich echt in den Wahnsinn. Habe ich das Problem einigermaßen verständlich beschrieben? Bis jetzt habe ich das Gefühl: NEIN laugh

Es muss doch ultra simpel sein, die getroffene ENTIY an (HIT_TARGET) zurück zu geben. Wozu sollte die Funktion sonst sein?

Last edited by Ditje; 08/02/10 18:37.
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