Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: Scene_init script and Object script  (Read 4074 times)

0 Members and 1 Guest are viewing this topic.

Birdline

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • Birdline Web Site
Scene_init script and Object script
« on: November 21, 2008, 11:56:51 AM »

Hi all,
As a newbe, I have a problem.

In a scene, I can move/rotate objects with the mouse and position them where ever I want.
This is controlled by the object's script (LeftClick, LeftRelease).
What I want to do is this.
When I move an object to a certain position, something must be done.

So I write a contition.

if (this.X<= somenumbers && this.Y==somenumber && ......)
{
   do something
}

The problem is that if I write this at the objects script (LeftRelease), it is working OK.
But if I write the contition at the scene_init.script, it does not.

In the scene_init.script, I used:

var Object1 = Scene.GetNode("objectname") //to get control of the object,
and the contition changed as:
if (Object1.X<= somenumbers && Object1.Y==somenumber && ......)
{
   do something
}

I must say that in scene_init.script, using Game.Msg(Object1.X) and Game.Msg(Object1.Y),
I see the updated position of the object.
But the contition doesn't work.

Any help?
Spyros

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Scene_init script and Object script
« Reply #1 on: November 21, 2008, 01:00:48 PM »

Can you post the actual code? This should work, as far as I can tell.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Birdline

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • Birdline Web Site
Re: Scene_init script and Object script
« Reply #2 on: November 21, 2008, 02:01:16 PM »

Well, the object (one of them) is spr2 and the spr2.script is:

#include "scripts\base.inc"

var IsLeftDown = false; //to control the LeftClick and LeftRelease
this.Rotatable = true; //Now we can rotate the object

var ObjRot; //the rotation angle
var ObjRotReset; //for reseting the rotation angle when 360

////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  IsLeftDown = true;

  while(IsLeftDown==true)
    {
       this.X = Game.MouseX;
       this.Y = Game.MouseY;
       Sleep(50);
    }
}

on "LeftRelease"
{
  IsLeftDown = false;
  this.X = this.X;
  this.Y = this.Y;

/////////////////////////////////////////////////////////

The scene_init.script is this:

#include "scripts\base.inc"

var Obj2Ent = Scene.GetNode("spr2");
actor.Active = false;

while (1)
{
Game.Msg(Obj2Ent.X); //the updated X
Game.Msg(Obj2Ent.Y); //the updated Y
Sleep(10);
}

if (Obj2Ent.X > 810 && Obj2Ent.X < 850 && Obj2Ent.Y > 400 && Obj2Ent.Y < 450)
{
   Obj2Ent.SkipTo(100,482); //just for testing
}

//////////////////////////////////////////////////////////////////

Thanks
Spyros

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Scene_init script and Object script
« Reply #3 on: November 21, 2008, 02:08:54 PM »

Your scene_init.script is stuck in the while(1) loop so it never actually reaches the condition. You probably intended to put the condition inside the while loop.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Birdline

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • Birdline Web Site
Re: Scene_init script and Object script
« Reply #4 on: November 21, 2008, 07:53:24 PM »

Mnemonic,

I removed the while loop.
But I does not work.
I made a new game with one empty scene. Put the same object.
Added the same 2 scripts. It does not work.
It only works if I put the contition in the object's script and not in the scene_init script.

Best regards,
Spyros

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Scene_init script and Object script
« Reply #5 on: November 21, 2008, 08:00:05 PM »

I don't know if I understand correctly, but you want the scene script to be periodically checking object's position, and if the position is within some range, you want to perform some action, right?

In that case you should not *remove* the loop, just move the condition inside.

Code: WME Script
  1. // get the object reference
  2. var Obj2Ent = Scene.GetNode("spr2");
  3.  
  4. // infinite loop, in the meantime the player is moving the object using some other script
  5. while (1)
  6. {
  7.   // check to see if the object reached the destination area
  8.   if (Obj2Ent.X > 810 && Obj2Ent.X < 850 && Obj2Ent.Y > 400 && Obj2Ent.Y < 450)
  9.   {
  10.      // it did, do something here
  11.   }
  12.   Sleep(10);
  13. }
  14.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Birdline

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • Birdline Web Site
Re: Scene_init script and Object script
« Reply #6 on: November 21, 2008, 09:13:28 PM »

Mnemonic,
You understood correctly.

As you pointed out, I moved the condition inside the loop and it worked.
But since the action was to actually move the object to another "correct" place,
when it reached the area defined by the condition, it flashes and seems stucked under the mouse.
I try to raise the Sleep to 200 and it seems to be working better (is this normal?)

Anyway, I will add the other objects to complete the scene and I will come again.

Thanks again for the help

Best regards,
Spyros
 

Page created in 0.077 seconds with 21 queries.