Gamestudio Links
Zorro Links
Newest Posts
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
2 registered members (AndrewAMD, Ayumi), 1,405 guests, and 4 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
Problem with events for entities with the same action #329266
06/18/10 21:01
06/18/10 21:01
Joined: Mar 2003
Posts: 3,010
analysis paralysis
NITRO777 Offline OP
Expert
NITRO777  Offline OP
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
Hello, I am having trouble running events for my entities in the following code I get the error "Crash in SYS",
I initially run an action which assigns a new entity_number to each model in WED with the action:
Code:
action entity_example()
{

   max_ents += 1; // get a unique entity number 
   my.skill99 = max_ents; // and store it inside skill99 (don't use skill99 for anything else)
	play(my.skill99); 
	
 
}





Code:
function my_event()
{

switch (event_type)
  {
    case EVENT_BLOCK:
      beep();
      gt=5;
      return;
    case EVENT_ENTITY: 
     beep();
      return;
  }

      
  }
  


action play(entity_number)
{	


	//my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY ) ; 
   //my.event = my_event();

	STRING* rec_str = "       "; // stores the name of the recorded data file
	STRING* temp_str = "  "; // just a temporary string
	var filehandle;
   
	str_cpy(rec_str, str_for_num(temp_str, entity_number)); // create the name of the data file depending on entity's number
	str_cat(rec_str, ".txt"); // and then add it the ".txt" extension
	filehandle = file_open_read(rec_str); // now we can try to open the file
    
   if (filehandle)
   {
   
		var temp = 0;
	   VECTOR tempStore;
      VECTOR tempStorePan;
      VECTOR tempVector;
      
      var spaceFind;
      var totalSpaces=0;
      var count=0;
		
		while(file_find(filehandle, " ")>=0)	count++;
  
      file_seek (filehandle, 0, 0);	// reset read position back  	
         
		   while(temp < count)
		   {
		 	   tempStore.x=file_var_read(filehandle);
			  	tempStore.y=file_var_read(filehandle);
			   tempStore.z=file_var_read(filehandle);
			   tempStorePan.x=file_var_read(filehandle);
			   tempStorePan.y=file_var_read(filehandle);
			   tempStorePan.z=file_var_read(filehandle);
			   my.frame = file_var_read(filehandle); // and put them inside the array
			   
          
			   // rotate towards target
				vec_set(tempVector, tempStore.x);
				vec_sub(tempVector, my.x);
				 vec_to_angle(my.pan, tempVector);
				
				//move to it with collision
			   c_move(my, vector(5 * time_step, 0, 0), nullvector, IGNORE_PASSABLE | GLIDE);

		
			 temp +=1;
			 wait(1);
			  
	      }
	      
	
		file_close(filehandle); // close the file
		beep();
   }	
    	
	
}



I wonder if it has anything to do with the fact that a file_var_read is reading from a file to supply the c_move? I have not had any luck trying to figure out why it wont work, any help is very much appreciated crazy

Thanks

Re: Problem with events for entities with the same action [Re: NITRO777] #329281
06/19/10 00:13
06/19/10 00:13
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Firstly, I dont know if "return;" is valid in events (ie my_event).
Change them to the more conventional "break;" instead.
With the code you have it will work exactly the same.
(NOTE :: this has nothing to do with your error...)

Secondly, change the string definitions 'rec_str' and 'temp_str' to
STRING* rec_str = str_create("_______"); // stores the name of the recorded data file
STRING* temp_str = str_create("___"); // just a temporary string

I hate seeing those retro definitions, and they can fail un-expectedly if the
data you put in them overflows.
(NOTE :: this MAY have something to do with your error...)

Thirdly, the name of the play function is not 'correct'.
I dont know if you are allowed to pass parameters to an "action'.
Change it to "function play(entity_number)" instead, for safety.
(NOTE :: this MAY have something to do with your error...)

And finally, and most concerning...
Are you certain that the ME/MY entitiy is alive the whole time?
In the "while(temp < count)" loop, every time you perform a "wait"
there is the chance that ME is no longer valid, but you are not checking.
If ME gets removed by some other function, this loop will still attempt
to change the pan and pos of ME, causing a crash.
(NOTE :: this MOST LIKELY is the cause of your error...)


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Problem with events for entities with the same action [Re: EvilSOB] #329284
06/19/10 00:45
06/19/10 00:45
Joined: Mar 2003
Posts: 3,010
analysis paralysis
NITRO777 Offline OP
Expert
NITRO777  Offline OP
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
Hi EvilSOB,
I think you should change your screen name to "pretty nice guy" grin

I tried 1,2,and 3 with no success, but you have definitely educated me. But just so you know I am not just posting questions about things which I am too lazy to research. I have been looking thoroughly for any answers in the manuals and I have searched the forum and code snippets for similar problems. I usually dont like to ask questions unless I just cannot proceed any further, and that is the awful predicament I find myself in here.


As for the number 4 I understand what you mean, but im not sure how I might perform a check to see if the ME is no longer valid. Is there any way you could explain it to me or point me in the right direction of an example? Just for the sake of completeness I have posted the new code below showing the changes I have already made:


Code:
action entity_example()
{

play((my.skill99=max_ents++));
  
 
}


Code:
function my_event()
{

switch (event_type)
  {
    case EVENT_BLOCK:
      beep();
      gt=5;
      break;
    case EVENT_ENTITY: 
     beep();
      break;
  }

      
  }
  


function play(entity_number)
{	


	my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY ) ; 
   my.event = my_event();
   
	STRING* rec_str = str_create("_______"); // stores the name of the recorded data file
	STRING* temp_str = str_create("___"); // just a temporary string


	var filehandle;
   
	str_cpy(rec_str, str_for_num(temp_str, entity_number)); // create the name of the data file depending on entity's number
	str_cat(rec_str, ".txt"); // and then add it the ".txt" extension
	
	
	filehandle = file_open_read(rec_str); // now we can try to open the file
    
   if (filehandle)
   {
   
		var temp = 0;
	VECTOR tempStore;
      VECTOR tempStorePan;
      VECTOR tempVector;
      
      var spaceFind;
      var totalSpaces=0;
      var count=0;
		
		while(file_find(filehandle, " ")>=0)	count++;
  
      file_seek (filehandle, 0, 0);	// reset read position back  	
         
		   while(temp < count)
		   {
		 	   tempStore.x=file_var_read(filehandle);
			  	tempStore.y=file_var_read(filehandle);
			   tempStore.z=file_var_read(filehandle);
			   tempStorePan.x=file_var_read(filehandle);
			   tempStorePan.y=file_var_read(filehandle);
			   tempStorePan.z=file_var_read(filehandle);
			   my.frame = file_var_read(filehandle); // and put them inside the array
			   
          
			   // rotate towards target
				vec_set(tempVector, tempStore.x);
				vec_sub(tempVector, my.x);
				 vec_to_angle(my.pan, tempVector);
				
				//move to it with collision
			   c_move(my, vector(5 * time_step, 0, 0), nullvector, IGNORE_PASSABLE | GLIDE);

		
			 temp +=1;
			 wait(1);
			  
	      }
	      
	
		file_close(filehandle); // close the file
		beep();
   }	
    	
	
}



Thanks again

Re: Problem with events for entities with the same action [Re: NITRO777] #329287
06/19/10 01:01
06/19/10 01:01
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Thats cool dude, but Im being helpful in order to increase evil...
The better you get at coding, the more frustrating your "next" problems
will become...
And when I stop helping ... thats when my evil intentions strike...

And as for only calling for help when really stumped, I understand. Im the same.
And I can see from your post-counter that its not lazy, its a true mental road-block.

Anyways, back on topic now...

Heres how to check thet the ME exists.
The PROC_GLOBAL is to prevent the entire function aborting when the ME vanishes.
Cause if the entire function aborts like that, the file gets left open...
Code:
...
if (filehandle)
{
   proc_mode = PROC_GLOBAL;
   ...
   while(temp < count)
   {
      if(!me)   break;     //abort reading if entity gone.
      ...
      wait(1);
   }
...




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Problem with events for entities with the same action [Re: EvilSOB] #329298
06/19/10 01:28
06/19/10 01:28
Joined: Mar 2003
Posts: 3,010
analysis paralysis
NITRO777 Offline OP
Expert
NITRO777  Offline OP
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
Hi,
So I understand why the "proc_mode = PROC_GLOBAL;" and if(!me) break; lines are included, so I would assume that it would be good to include this error checking feature in any while loop of an entity? It seems to be a good method.

But the program still crashes as soon as the model collides with a block or entity, I'll post the entire code, it is not much more lines than I have already included, but maybe after you see the other few lines can see what I missed..

There are only 2 files to the program: 1)level_1.c and play_2.c, the level is just a great square hollowed out block
with two models in it one assigned the players_code() action and 1 assigned the entity_example()

Note that a lot of the code from level_1.c has been commented out because it was taken from one og George's articles. Tomorrow I will clean it up a little better.
level_1.c
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>
///////////////////////////////
#include "play_2.c"



function main()
{
	level_load("level_1.WMB");
	wait(2);
	//printf("Press [0] to move the camera!");
   fps_max = 70;
	video_mode = 8; // run in 800 x 600 pixels
	video_depth = 32; // 32 bit mode
	video_screen = 2; // start in full screen mode
	time_smooth = 0.9; // use a time_step value that is the average of the last 10 frames to smooth the replayed movement
	//level_load (test_wmb);
	// the quit_game function deletes the previously saved data files as well - examine recreplay.c to see its code
	//on_esc = sys_exit(NULL); // now we can safely shut down the engine 
	
}


action players_code() // simple (flying!) player and 1st person camera code
{ 
	// these 3 lines have to be added to every entity that needs to be recorded
	//max_ents += 1; // get a unique entity number 
   //my.skill99 = max_ents; // and store it inside skill99 (don't use skill99 for anything else)
	//record_me(my.skill99); // put this line here
	// these 3 lines have to be added to every entity that needs to be recorded
   //mouse_mode=2;
	player = my; // I'm the player
	set (my, INVISIBLE); // no need to see player's model in 1st person mode
	//set (my, PASSABLE);
	while (1)
	{
		//if (mode != REPLAYING) // this is your regular entity code
		//{
			// move the player using the "W", "S", "A" and "D" keys; "10" = movement speed, "6" = strafing speed
			c_move (my, vector(10 * (key_w - key_s) * time_step, 6 * (key_a - key_d) * time_step, 0), nullvector, GLIDE);
			vec_set (camera.x, player.x);
			player.pan -= 5 * mouse_force.x * time_step; // rotate the camera around by moving the mouse
			player.tilt += 3 * mouse_force.y * time_step;
			camera.pan = player.pan; // the camera and the player have the same angles
  			camera.tilt = player.tilt;
			camera.roll = player.roll;
		//}
		// we need this "else" section because the recreplay.c code moves the player entity and not the camera
		// this is the playback code; the camera copies player's values, which were stored in player's recorded data file
		//else 
		//{
		//	camera.x = my.x;
		//	camera.y = my.y;
		//	camera.z = my.z;
		//	camera.pan = my.pan;
		//	camera.tilt = my.tilt;
		//	camera.roll = my.roll;
		//}
		wait (1);
	}
}





action entity_example()
{

play((my.skill99=max_ents++));
  
 
}



play_2.c:
Code:
var max_ents = 0; // this variable stores the maximum number of entities
var recorded_position[70000][50]; // stores x y z pan tilt roll frame for 10,000 frames and up to 50 different entities
var pause_replay[50];


BMAP* cursor_tga = "cursor.tga";

function mouse_startup()
{  
   mouse_mode = 0;
   mouse_map = cursor_tga;
   while (1)
   {  
        vec_set(mouse_pos, mouse_cursor);
        wait(1);
   }
}	

var gt=0;
function my_event()
{

switch (event_type)
  {
    case EVENT_BLOCK:
      beep();
      gt=5;
      break;
    case EVENT_ENTITY: 
     beep();
      break;
  }

      
  }
  


function play(entity_number)
{	


	my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY ) ; 
   my.event = my_event();
   
	STRING* rec_str = str_create("_______"); // stores the name of the recorded data file
	STRING* temp_str = str_create("___"); // just a temporary string


	var filehandle;
   
	str_cpy(rec_str, str_for_num(temp_str, entity_number)); // create the name of the data file depending on entity's number
	str_cat(rec_str, ".txt"); // and then add it the ".txt" extension
	
	
	filehandle = file_open_read(rec_str); // now we can try to open the file
    
   if (filehandle)
   {
   
      proc_mode = PROC_GLOBAL;
      
		var temp = 0;
	   VECTOR tempStore;
      VECTOR tempStorePan;
      VECTOR tempVector;
      
      var spaceFind;
      var totalSpaces=0;
      var count=0;
		
		while(file_find(filehandle, " ")>=0)	count++;
  
      file_seek (filehandle, 0, 0);	// reset read position back  	
         
		   while(temp < count)
		   {
            if(!me)   break;     //abort reading if entity gone.
		   	
		 	   tempStore.x=file_var_read(filehandle);
			  	tempStore.y=file_var_read(filehandle);
			   tempStore.z=file_var_read(filehandle);
			   tempStorePan.x=file_var_read(filehandle);
			   tempStorePan.y=file_var_read(filehandle);
			   tempStorePan.z=file_var_read(filehandle);
			   my.frame = file_var_read(filehandle); // and put them inside the array
			   
          
			   // rotate towards target
				vec_set(tempVector, tempStore.x);
				vec_sub(tempVector, my.x);
				 vec_to_angle(my.pan, tempVector);
				
				//move to it with collision
			   c_move(my, vector(5 * time_step, 0, 0), nullvector, IGNORE_PASSABLE | GLIDE);

		
			 temp +=1;
			 wait(1);
			  
	      }
	      
	
		file_close(filehandle); // close the file
		beep();
   }	
    	
	
}



Re: Problem with events for entities with the same action [Re: NITRO777] #329331
06/19/10 03:40
06/19/10 03:40
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Mwwaahaaaa! Such a hideous looking error from such a simple typo !?!

Check the manual after checking the line
my.event = my_event();

Click to reveal..
you want to be setting the my.event to a POINTER to the my_event function,
not to the RESULT of the my_event functin being executed...

my.event = my_event; that is...



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Problem with events for entities with the same action [Re: EvilSOB] #329354
06/19/10 11:14
06/19/10 11:14
Joined: Mar 2003
Posts: 3,010
analysis paralysis
NITRO777 Offline OP
Expert
NITRO777  Offline OP
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
WOW. It works. You have to be kidding me! So in essence I was setting the my.event to a result by having the parenthesis. Unbelievable. Thank you. Thank you. Thank you. I will never make that mistake again.

Re: Problem with events for entities with the same action [Re: NITRO777] #329358
06/19/10 11:22
06/19/10 11:22
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Yes you will... it just happens.
I always suffer the same typo when setting on_key functions.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Problem with events for entities with the same action [Re: EvilSOB] #329360
06/19/10 11:28
06/19/10 11:28
Joined: Mar 2003
Posts: 3,010
analysis paralysis
NITRO777 Offline OP
Expert
NITRO777  Offline OP
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
Yes your right, what I meant is that I will know to check for it next time, I will never forget what I learned here. All thanks to you.

Re: Problem with events for entities with the same action [Re: NITRO777] #329361
06/19/10 11:34
06/19/10 11:34
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Anytime dude. I gain extreme pleasure in pointing out other peoples faults!

Anyone would think Im a woman! [snigger, snigger]


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

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