Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: keyboard movement  (Read 4034 times)

0 Members and 1 Guest are viewing this topic.

Rocco

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 87
    • View Profile
    • Virtual-Illusion
keyboard movement
« on: September 09, 2004, 03:46:40 PM »

i cant get this script to work:
http://forum.dead-code.org/index.php?topic=615.0

i have
  SCRIPT="scripts\direct_control.script"
in the default.game script

and the direct_control.script in the scripts folder, with updated actor:
 actor.PlayAnimAsync("actors\Dave\ll\walk.sprite");
          break;

but nothing happens, when i use the keys
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: keyboard movement
« Reply #1 on: September 09, 2004, 05:03:27 PM »

i have
  SCRIPT="scripts\direct_control.script"
in the default.game script

Did you attach the script in ProjectMan or did you edit the default.game file by hand? It's not a good idea to edit ths file directly if the project is open in ProjectMan, because all changes will be overwritten.

I tried to create a new project, copied the direct_control.script to scripts folder, attached in ProjectMan and it works ok, so I suspect it's the above case..? I can upload the project if needed.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Rocco

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 87
    • View Profile
    • Virtual-Illusion
Re: keyboard movement
« Reply #2 on: September 09, 2004, 06:30:35 PM »

I attached the file, without edit the default.game script by hand, cause i realized that theres no way to save the changes.
I made a test file:  http://www.virtual-illusion.com/test.zip
im new to wme so i guess its a mistake cause i dont understand exactly, how the scripts fit together right now.
thanks for helping
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: keyboard movement
« Reply #3 on: September 09, 2004, 07:03:33 PM »

The problem is in the movement.script. You probably forgot to copy the CanMoveThere function from the original thread.

The entire movement.script should look like this:

Code: [Select]

#include "scripts\base.inc"
#include "scripts\keys.inc"

var TargetX, TargetY;

var LastDir = -1;
var CurrentDir = -1;

while(true)
{
  // get a requested direction depending on pressed-down keys
  if     (Keyboard.IsKeyDown(VK_LEFT)  && Keyboard.IsKeyDown(VK_UP))   CurrentDir = DI_UPLEFT;
  else if(Keyboard.IsKeyDown(VK_LEFT)  && Keyboard.IsKeyDown(VK_DOWN)) CurrentDir = DI_DOWNLEFT;
  else if(Keyboard.IsKeyDown(VK_RIGHT) && Keyboard.IsKeyDown(VK_UP))   CurrentDir = DI_UPRIGHT;
  else if(Keyboard.IsKeyDown(VK_RIGHT) && Keyboard.IsKeyDown(VK_DOWN)) CurrentDir = DI_DOWNRIGHT;
 
  else if(Keyboard.IsKeyDown(VK_LEFT))  CurrentDir = DI_LEFT;
  else if(Keyboard.IsKeyDown(VK_RIGHT)) CurrentDir = DI_RIGHT;
  else if(Keyboard.IsKeyDown(VK_UP))    CurrentDir = DI_UP;
  else if(Keyboard.IsKeyDown(VK_DOWN))  CurrentDir = DI_DOWN;
  else CurrentDir = -1;

  if(CurrentDir==LastDir)
  {
    // check for blocked areas
    if(!CanMoveThere(CurrentDir)) actor.Reset();
  }
  else
  {
    // start walking
    if(CurrentDir==-1 || !CanMoveThere(CurrentDir)) actor.Reset();
    else
    {
      actor.TurnTo(CurrentDir);
      switch(CurrentDir)
      {
        case DI_LEFT:
          actor.PlayAnimAsync("actors\molly\ll\walk.sprite");
          break;
        case DI_RIGHT:
          actor.PlayAnimAsync("actors\molly\rr\walk.sprite");
          break;
        case DI_UP:
          actor.PlayAnimAsync("actors\molly\uu\walk.sprite");
          break;
        case DI_DOWN:
          actor.PlayAnimAsync("actors\molly\dd\walk.sprite");
          break;
        case DI_UPRIGHT:
          actor.PlayAnimAsync("actors\molly\ur\walk.sprite");
          break;
        case DI_UPLEFT:
          actor.PlayAnimAsync("actors\molly\ul\walk.sprite");
          break;
        case DI_DOWNRIGHT:
          actor.PlayAnimAsync("actors\molly\dr\walk.sprite");
          break;
        case DI_DOWNLEFT:
          actor.PlayAnimAsync("actors\molly\dl\walk.sprite");
          break;               
      }
    }
  }
 
  LastDir = CurrentDir;
 
  Sleep(20); 
}


function CanMoveThere(Direction)
{
 var CanMove = true;

 switch(Direction)
 {
  case DI_LEFT:
   if(!Scene.IsWalkableAt(actor.X-15,actor.Y)) CanMove = false;
   break;
  case DI_RIGHT:
   if(!Scene.IsWalkableAt(actor.X+15,actor.Y)) CanMove = false;
   break;
  case DI_UP:
   if(!Scene.IsWalkableAt(actor.X,actor.Y-15)) CanMove = false;
   break;
  case DI_DOWN:
   if(!Scene.IsWalkableAt(actor.X,actor.Y+15)) CanMove = false;
   break;
  case DI_UPRIGHT:
   if(!Scene.IsWalkableAt(actor.X+15,actor.Y-15)) CanMove = false;
   break;
  case DI_UPLEFT:
   if(!Scene.IsWalkableAt(actor.X-15,actor.Y-15)) CanMove = false;
   break;
  case DI_DOWNRIGHT:
   if(!Scene.IsWalkableAt(actor.X+15,actor.Y+15)) CanMove = false;
   break;
  case DI_DOWNLEFT:
   if(!Scene.IsWalkableAt(actor.X-15,actor.Y+15)) CanMove = false;
   break;       
 }
 return CanMove;

}

You were missing the last part.

If there is some problem with your game, always check the wme.log file in your project folder. It logs any runtime errors which is often very useful.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Rocco

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 87
    • View Profile
    • Virtual-Illusion
Re: keyboard movement
« Reply #4 on: September 09, 2004, 08:27:30 PM »

big thanks, it works fine
im a sleepy head today.
Logged

tinchopunk

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 90
    • View Profile
    • martinarregui.tumblr.com
Re: keyboard movement
« Reply #5 on: December 16, 2004, 04:03:11 AM »

ok i do it for the 3d character but only sty in the place and make some rotation...don´t move foward...
any help for 3dcharacter to move with keys..
thanks
 MArtin
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: keyboard movement
« Reply #6 on: December 16, 2004, 08:42:02 AM »

ok i do it for the 3d character but only sty in the place and make some rotation...don´t move foward...
any help for 3dcharacter to move with keys..
thanks
 MArtin
As I said in the other thread, there will be better scripting support for keyboard control for 3D characters in the next WME build. It's already implemented, please wait a few days for the next release. Thanks.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

tinchopunk

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 90
    • View Profile
    • martinarregui.tumblr.com
Re: keyboard movement
« Reply #7 on: December 17, 2004, 12:09:48 AM »

ok well i will be waiting that
thanks
 MArtin
Logged
 

Page created in 0.031 seconds with 23 queries.