Whats the problem with this code? Yet another...

Posted By: Delirium

Whats the problem with this code? Yet another... - 11/03/11 21:45

Alright I know you're sick of hearing about problems writing
lite-C player walk routines. I just bought A8 commercial and long wistfully for the days of ease writing WDL for A6,A5. I tried suggestions and have sought to use player routines from tutorials, from the built in help, from the wiki. Has anyone ever actually written a working player walk routine in lite C where the character doesn't fall through the floor, float up helplessly or pass through walls? Is there a tutorial series in the AUM magazine that takes you through building a simple game with a walking character? I'll look. In the meantime, here is the code that's currently giving me trouble. The level won't run, stops with an error on while(1) although I think my brackets are all there.....

Code:
action player_walk()
   while (1)
   {
// rotate the player using the [A] and [D] keys      
      my.pan += 5*(key_a-key_d)*time_step; 

// determine the ground distance by a downwards trace
      var dist_down; 
      if (c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_ME | IGNORE_PASSABLE | USE_BOX) > 0)
         dist_down = my.z + vFeet.z - target.z; // get distance between player's feet and the ground
      else
         dist_down = 0;

// apply gravity when the player is in the air
      if (dist_down > 0)  // above floor, fall down with increasing speed
         dist_down = clamp(dist_down,0,accelerate(speed_down,5,0.1));
      else                // on or below floor, set downward speed to zero
         speed_down = 0;

// move the player using the [W] and [S] keys      
      var dist_ahead = 5*(key_w-key_s)*time_step;
      dist_ahead = sign(dist_ahead)*(abs(dist_ahead) + 0.5*dist_down); // adapt the speed on slopes
      c_move(me,vector(dist_ahead,0,0),vector(0,0,-dist_down),IGNORE_PASSABLE | GLIDE); // move the player

// animate the player according to its moved distance
      if (dist_ahead != 0) // player is moving ahead
      {
         anim_percent += 1.3*dist_ahead; // 1.3 = walk cycle percentage per quant
         ent_animate(me,"walk",anim_percent,ANM_CYCLE); // play the "walk" animation
      }
      else // player stands still
      { 
         anim_percent += 5*time_step; 
         ent_animate(me,"stand",anim_percent,ANM_CYCLE); // play the "stand" animation
      }
      wait(1);
   }


Posted By: Pappenheimer

Re: Whats the problem with this code? Yet another... - 11/03/11 22:31

You don't have any bracket before the while, after the function's name
Posted By: Redeemer

Re: Whats the problem with this code? Yet another... - 11/03/11 22:49

Originally Posted By: Delirium
Has anyone ever actually written a working player walk routine in lite C where the character doesn't fall through the floor, float up helplessly or pass through walls?

Nah. We've always just called these features. wink

In all seriousness, you're missing two brackets: one at the beginning of the function definition, and the other at the end. laugh

EDIT: Also I suggest that you change that "while(1)" condition to a "while(my)" condition so that your game doesn't crash if/when the entity is removed from the level.

EDIT2: Oh, sorry. You do have the bracket at the end. It's a little hard to tell without any indentations. In the future, could you place any code you have written into some [code] tags?
Posted By: Delirium

Re: Whats the problem with this code? Yet another... - 11/04/11 11:52

Thanks for pointing out what I should have noticed. I used to think I was brilliant. I could program computers to do anything in machine language. My idea of a vacation is still to get a hotel room for a week and take a laptop and some computer manuals. I can't believe how incomprehensible Gamestudio has become. I wish I was a gifted 24 year old C programmer hopped up on energy drinks, then maybe I could do this. I'm good at constructing amazing looking levels, and no good at writing walk routines. If I can just get the walking right, then it will only be one problem at a time adding interactions between the player and objects. Seriously, if anyone knows of the complete code for a simple game example with a working walk routine that runs in A8, please direct me to it. Thank you for your replies. I'll go back and fix the brackets and try this player code again.
Posted By: painkiller

Re: Whats the problem with this code? Yet another... - 11/04/11 11:55

you can try the shooter template from latest aum 103, you can use that script to try your own levels, and don't forget to keep checked the flag "create meshes" in the map compiler
Posted By: Delirium

Re: Whats the problem with this code? Yet another... - 11/04/11 17:41

Thank you for the idea to download Aum 103 again and use the shooter code. I d forgotten when I first tried that, the player actually did walk through correctly. I do get an error tho which brings to running game to a crash, when I press space and jump. Before, I download that code/demo and when I used it for my own constructed level, that's when I started flying up, up and away. I'll cautiously try remodeling it.

Added by edit: Here is a video I made using A6 and fraps.
http://www.youtube.com/user/masterdelirium#p/a/u/1/U0rjvE2WFPI

I was going to make an entire film but got bogged down making the animated characters. Its kind of corny but "Dr. Frankenstein's village" was very detailed. The Cathedral front was good and I even had a nice funeral procession with the free Max Payne mdl's carrying the coffin. I no longer use the "Master Delirium" name on you tube as someone else uses something identical. I include this link just to show I'm not totally clueless about Gamestudio.
© 2024 lite-C Forums