Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (NewbieZorro, TipmyPip, 1 invisible), 19,045 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
How to open up inventory and freeze movement? #429794
09/18/13 17:43
09/18/13 17:43
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
I am trying to make it so that my player can move normally as usual, but when the player presses the "i" key, I want the player's inventory to show, I want the mouse cursor to appear in order to manipulate the inventory, and I want the player's movement to cease, all happening simultaneously. If the player presses the "i" key a second time, I want the inventory to close, the mouse cursor to disappear, and the player be able to move again normally.

Here is the code I am using to try and make this happen

Code:
var bag_i_counter = 0;

function change_mouse_mode()
{
   mouse_mode += 1;
   mouse_mode %= 2;
   if (1 == mouse_mode)
      mouse_map = cursor_pcx;
}

...

if(key_i)
{	
  bag_i_counter = 1;
				
  if(bag_i_counter == 1)
  {
    inv_open_bag(bag, 500, 0);
    mouse_mode = 1;
					
    if(key_i)
    {
      bag_i_counter = 0;
						  
      inv_close_bag(bag);
      mouse_mode = 0;
    }
  }
}


When I run this code, all I see is this error box stating this:

Error E1512
Empty function called in inv_open_bag

I press the OK button, but nothing happens. The inventory does not show up, the mouse cursor does not show up, and my player can still move about as normal.

****************

Keep in mind that I do not have a fully functioning inventory yet. I am including the "inventory.c" code by Bret Truchan. In the past, when I pressed the "i" key, the only thing that happened was I got the same error message above.

When I pressed the OK button on this error box, I saw a horizontal row of images that I placed in the inventory slots using my Lite-C code, and was even able to drag the first image from the row across the screen.


Last edited by Ruben; 09/18/13 17:44.
Re: How to open up inventory and freeze movement? [Re: Ruben] #429795
09/18/13 18:07
09/18/13 18:07
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Why not post the function where its actually crashing?
Also the code looks verrry unclean (f.e. 2 times check for key_i or a varibale with no use etc..)

Re: How to open up inventory and freeze movement? [Re: Ch40zzC0d3r] #429812
09/19/13 05:20
09/19/13 05:20
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Here's the full function where the crash occurs:

Code:
action walking_guard()
{
  player = me;
	
  vec_fill(move_vec, 0); // always reset a vector to zero when creating
	
  var bag_i_counter = 0;
	
  my.JUMP_FORCE = 13;
  var gravity_var = 0;
  var gravity_force = 2;
  var jumplck = 0;
  var space_lck = 0;
  my.FEET_HEIGHT = -my.min_z+1; 
   
  my.eflags |= FAT | NARROW; // set both flags to prevent automatic 
                             //   recalculation on scale changes.
  my.emask |= ENABLE_SHOOT;
  my.event = spell_fly_damage;

  my.HEALTH = 500;
	
  // set FLAG2 to make the guard detectable by c_scan, 
  // and store the guard pointer in its own CREATOR skill 
  // so that the detecting entity knows its enemy	
  set(my,FLAG2);  
  my.CREATOR = me;
	 
  set(my, POLYGON);
  
  camera.tilt = -5;
  
  my.STATE = 1;
	 
  while(my.x)
  {
    player_health();
		
    // state 1: walking ////////////////////////////////////////////
		
    if (my.STATE == 1)
    {
      while(mouse_mode == 1)
      {
        move_vec.x = 0;
        move_vec.y = 0;
		   	
        wait(1);
      }
	   	 
      // MOVE PLAYER FORWARD/BACKWARD WITH "W" AND "S" KEYS, AND SIDEWAYS WITH 
      //   "A" AND "D" KEYS
      move_vec.x = key_w - key_s;
      move_vec.y = key_a - key_d;
		  
	
      // MOVING FORWARD/BACKWARD KEYS - OPTIONS: UP AND DOWN ARROW KEYS, OR "W" 
      //   AND "S" KEYS
			
      distance = (key_w-key_s)*20*time_step; 
      distance_crawl = (key_w-key_s) * 5 * time_step;
			
      if(key_i)
      {	
        bag_i_counter = 1;
				
        if(bag_i_counter == 1)
        {
          inv_open_bag(bag, 500, 0);
	  mouse_mode = 1;
					
	  if(key_i)
	  {
	    bag_i_counter = 0;
	    inv_close_bag(bag);
	    mouse_mode = 0;
	  }
        }
      }
			
      // JUMPING CODE
      if( (key_space)  && !space_lck && !jumplck)
      {
        gravity_var = my.JUMP_FORCE;
        jumplck = 1;
        my.ANIMATION = 0;
      }
      space_lck = key_space;
      gravity_var -= gravity_force * time_step;
	      
      // RUNNING
      vec_normalize(move_vec, 20 * time_step); // normalize the vector - 
        //  otherwise walking forward and sideways at the same time will be 
        //  faster (~1.4151x)
			
      c_move(me, move_vec, vector(0, 0, gravity_var), IGNORE_PASSABLE | GLIDE); 
			
      _handle_cam_3rdperson();
			  
      if(((key_w == 1) || (key_s == 1)) && (mouse_right == 0))
      {
        // FORWARD/BACKWARD MOVEMENT ANIMATION    
				
        my.ANIMATION += 1*distance;
				
        ent_animate(me,"run",my.ANIMATION,ANM_CYCLE);
      }
      else
      if(((key_w == 1) || (key_s == 1) || (key_a == 1) || (key_d == 1)) && 
        (mouse_right == 1))
      {
        // CRAWLING  
        vec_normalize(move_vec, 5 * time_step); // normalize the vector - 
          //  otherwise walking forward and sideways at the same time will be 
          //  faster (~1.4151x)  
				
        // FORWARD/BACKWARD MOVEMENT ANIMATION    
				
        my.ANIMATION += 1*distance_crawl;
				
        ent_animate(me,"crawl",my.ANIMATION,ANM_CYCLE);
      }
      else
      if(mouse_right == 1)
      {
        // FORWARD/BACKWARD MOVEMENT ANIMATION    
				
        my.ANIMATION += 1*distance;
				
        ent_animate(me,"crouch",my.ANIMATION,ANM_CYCLE);
      }
      else
      {
        // STANDING STILL ANIMATION
				
        my.ANIMATION += 1*time_step;
        ent_animate(me,"idle",my.ANIMATION,ANM_CYCLE); // "idle" stance 
          //  continual animation
      }
			
      // adjust entity to the ground height, using a downwards trace

      if(c_trace(my.x, vector(my.x, my.y, my.z - my.FEET_HEIGHT), IGNORE_ME | 
        IGNORE_PASSABLE | IGNORE_PASSENTS | USE_POLYGON))
      {
        my.z = target.z + (my.FEET_HEIGHT);	
        gravity_var = 0;
        jumplck = 0;	
      }	
			
      // ATTACK CODE
		
      if (mouse_left) 
      { // key pressed -> go to state 2
        my.ANIMATION = 0;
        my.STATE = 2;
      }
			
      // state 2: guard swing attacking /////////////////////////////////// 
      if (my.STATE == 2) 
      {	
        while (1)
        {
          my.ANIMATION += 15*time_step;
          ent_animate(me,"attack",my.ANIMATION,0); // "attack" one-shot   
            //  animation
     	  if (my.ANIMATION > 100) // finish the attack swing and go to state 3
          { 
            while(1)
     	    {
     	      player_ctrace();
     	
     	      my.ANIMATION -= 35*time_step;
     						
              ent_animate(me,"attack",my.ANIMATION,0); // "attack" one-shot   
                //  animation
     						
     						
     	      if (my.ANIMATION <= 0)
     	      {							
     	        my.STATE = 3;
     	        break;
     	      }
     	      wait(1);
	    }		
	  }
					
          if (my.STATE == 3)
	  {
	    my.ANIMATION = 0;
	    my.STATE = 1;
	    break;
          }
						
     	  wait (1);	
        }	
      }  
		
      // DEATH OF PLAYER CODE
		
      if (my.HEALTH <= 0)
      {
        my.ANIMATION = 0;
        while(1)
        {
          ent_animate(me,"death",my.ANIMATION,0);
	  my.ANIMATION += 5*time_step;
	
          if (my.ANIMATION >= 100)
            return;
	  wait(1);
        }
      }			
    }	
    wait(1);
  }
}


Re: How to open up inventory and freeze movement? [Re: Ruben] #429814
09/19/13 06:29
09/19/13 06:29
Joined: Jun 2013
Posts: 108
Alberta, Canada
C
CanadianDavid Offline
Member
CanadianDavid  Offline
Member
C

Joined: Jun 2013
Posts: 108
Alberta, Canada
Well there's probably something wrong with the way inv_open_bag and inv_close_bag functions are working. Not sure how those functions are defined, but the logic doesn't look too nice; an if(key_i) inside another if(key_i) doesn't look like a good technique.

Re: How to open up inventory and freeze movement? [Re: CanadianDavid] #429815
09/19/13 06:41
09/19/13 06:41
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Okay, so if you wanted to open your inventory using the "i" key, and also close the same inventory by pressing the "i" key again, do you have a method that you would suggest using, rather than placing an if(key_i) inside of another if(key_i)?

Re: How to open up inventory and freeze movement? [Re: CanadianDavid] #429816
09/19/13 06:43
09/19/13 06:43
Joined: Jul 2008
Posts: 2,110
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,110
Germany
Quote:
but the logic doesn't look too nice
+1

I dont get the logic of this
Code:
bag_i_counter = 1;
				
  if(bag_i_counter == 1)
  {
    inv_open_bag(bag, 500, 0);
    mouse_mode = 1;
					
    ..

First u set it to 1 then u check if its 1 ? Do u want to prevent a double start of this part ? If so this wont work this way in while. Without testing it, it needs to look like this fex
Code:
if(key_i)
      {	
        bag_i_counter = 1;
	          inv_open_bag(bag, 500, 0);
	  mouse_mode = 1;
			
        while(bag_i_counter == 1)
        {					
	  if(key_i)
	  {
	    bag_i_counter = 0;
	    inv_close_bag(bag);
	    mouse_mode = 0;
            break;
	  }
          wait (1);
        }
      }

This would pause player movement btw.

Last edited by rayp; 09/19/13 06:46.

Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
Re: How to open up inventory and freeze movement? [Re: rayp] #429833
09/19/13 09:04
09/19/13 09:04
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
@ rayp: I tried your code, but it has the same result as mine did.

Re: How to open up inventory and freeze movement? [Re: rayp] #429838
09/19/13 09:24
09/19/13 09:24
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
Waiting for "I" key...

Code:
if(key_i)
      {	
          bag_i_counter = 1;
	  inv_open_bag(bag, 500, 0);
	  mouse_mode = 1;
	  while(key_i == 1) { wait(1); }
          while(key_i == 0) { wait(1); }
	  bag_i_counter = 0;
	  inv_close_bag(bag);
	  mouse_mode = 0;
        }
      }



And , you'll always see the same result(crash) until you post your inv_open_bag function or find out yourself why it is crashing. There is a problem (my guess...) with the method of calling the function.


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: How to open up inventory and freeze movement? [Re: EpsiloN] #429841
09/19/13 09:39
09/19/13 09:39
Joined: May 2009
Posts: 5,377
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
What is the big deal behind this anyway guys??
Why don't you simply do this like this (this will works for 100%, cause this is how I've done it in my inventory):
Code:
// switch to toggle inventory:
void toggleInventory(){
	// put some comperisions here:
	// f.e. if we are dead, don't allow to toggle inventory:
	if(player.health <= 0){ return; }
	// toggle var:
	invOpen += 1;
	invOpen %= 2;
	// if we've opened the intentory:
	if(invOpen == 1){
		// show the mouse pointer:
		mouse_mode = 2;
	}
	else{
		// hide the mouse:
		mouse_mode = 0;
	}
}

// players actions:
action heroDude(){
	// toggle inventory:
	on_i = toggleInventory;	
	// player's loop:
	while(my.health > 0){
		// .......
		// .......
		// .......
		// if inventory closed:
		if(invOpen == 0){
			// allow to move:
			force.x = 10 * (key_w - key_s) * time_step;
			force.y = 10 * (key_a - key_d) * time_step;
			force.z = 0;
		}
		else{
			// if it was open, stop movement:
			vec_set(force.x, nullvector);
		}
		// .......
		// .......
		// .......
		// wait one frame:
		wait(1);
	}
}


// main game function:
void main(){
	// .......
	// .......
	// .......
	// main game loop:
	while(1){
		// .......
		// .......
		// .......
		// if we've enabled the mouse:
		if(mouse_mode > 0){
			// move it's position with a cursor:
			vec_set(mouse_pos.x, mouse_cursor.x);
		}
		// wait one frame:
		wait(1);
	}
}

Why are you trying to make things complicated? Make it easier instead laugh


Greets

Last edited by 3run; 09/19/13 09:45. Reason: ADDED MOUSE CURSOR!

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: How to open up inventory and freeze movement? [Re: EpsiloN] #429842
09/19/13 09:41
09/19/13 09:41
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
@ EpsiloN: I tried your code as well. Your code does open up the inventory, and shows the four images I placed in the inventory. However, I cannot see the mouse cursor when I move the mouse. Also, when I press the "i" key a second time, nothing happens. I still see the inventory images.

Page 1 of 2 1 2

Gamestudio download | 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