Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Window method  (Read 6442 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
Window method
« on: December 05, 2008, 09:34:27 PM »

I will try to explain one problem I have.
I have a window that is loaded in game script (hidden for some scenes, visible for some others).
This window has (among others) one static object that must be moving from one side to the other.
This movement must start when ever I click on an object in a scene and must stop when ever I click on an other object.

So, I made a method for the window which takes care of the movement (usual loop) and checks if a trigger is true.
For the objects, one sets the trigger to true and calls the method, and the other simply stops the trigger.
This is working fine, but I have this problem.

1. I am in Scene A,
2. I start the trigger (click on object_1),
3. the movement starts,
4. I move to Scene B,
5. the movement continues,
6. I stop the trigger (click on object_2),
7. the movement stops.

Every thing seems OK, BUT
Looking at the Debug console I see that the method is still there  ???

If I do the same again, then another method is stucked after the previous and so on.
At any time the movement is happening normally.

I don't have this issue if I don't change scene.
I mean that if I start/stop the trigger in the same scene,
at the Debug console the method clears each time the trigger is stoped.

Spyros

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Window method
« Reply #1 on: December 05, 2008, 11:03:35 PM »

So the method is in the window script? How does it look like?
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: Window method
« Reply #2 on: December 06, 2008, 10:09:28 AM »

The method is in a script that is attached to the window.
I mean : Window Editor > Behavior > Scripts > "this script".

"this script" :

#include "scripts\base.inc"
method HealthBarDown(Dur)
{
   for (var a=HealthBar.Y; a<=310; a=a+1)
 {
 if (DeathTrigger==true)   
   {
     this.Visible = true;
     HealthBar.Y = a;
     Sleep(Dur);
   }
 }
}

method HealthBarUp()
{
   //HealthBar.Y = HealthBar.Y;
   HealthBar.Y = 0;
   //this.Visible = false;
}

The whole idea is to design basically a Health system (Life/Death)
(the second method is for future use)
To give you an example, I have 2 objects in a scene.
The first starts the system (it is a region):
on "ActorEntry"
{
DeathTrigger = true;
Game.AttachScript("scripts\death.script");
HealthWin.HealthBarDown(100);
}
The second stops it:
on "LeftClick"
{
DeathTrigger = false;
Game.DetachScript("scripts\death.script");
this.Interactive = false;
}
(Well there is also a script that is attached/detached which ends the game, but it is not necessary for the example)

Now, if I start the system (with first object), then go to another scene,
return back and stop it (with the second object), then I have the stacked method "problem".

If I do the same but stay in the same scene, no problem.
In any case, the whole system works fine, except that "problem".

Best regards,
Spyros

Birdline

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • Birdline Web Site
Re: Window method
« Reply #3 on: December 06, 2008, 10:45:32 AM »

this is a screen shot of debug console (after start/stop several times)



Spyros

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Window method
« Reply #4 on: December 07, 2008, 09:20:36 AM »

I'll look into it.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Window method
« Reply #5 on: December 07, 2008, 10:08:51 AM »

Oh wait, I'm not sure I understand the concept wholly. You keep attaching new scripts, and they are probably never detached. You don't need to load new scripts all the time. Only attach it once. That makes the contained methods available until the script is explicitly unloaded.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

lacosaweb

  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 116
    • View Profile
Re: Window method
« Reply #6 on: January 04, 2012, 01:00:44 PM »

Hi, I have the same problem but this solution can't be applied to my game.

I have some overriten methods, one of them is Game.ChangeScene, this method is attached in Game object and I can't detach it because I need it allways accessible.

I attached it only one time, at game startup, but sometimes, after changing scene, the method script is still showing in debug console (like screenshot of Birdline) but all the code of this method is executed and finished. Why many script methods of the same are still in debug console if its execution is finished?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Window method
« Reply #7 on: January 04, 2012, 09:38:57 PM »

I would actually advise against overriding ChangeScene. This method is "special" in a way, because it merely schedules the scene change until the game processes next frame, and I'm afraid overriding the method will conflict with this scheduling.
What are you using the override for?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

lacosaweb

  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Posts: 116
    • View Profile
Re: Window method
« Reply #8 on: January 05, 2012, 05:19:22 PM »

One method that is still showing in debug console is "InventoryVisible", this isn't override method.



This method opens and close inventory using fade effect. It's attached into Game object, the code is:

Code: [Select]
method InventoryVisible(opt)
{
var InvWindow = Game.GetInventoryWindow();
var i;
if (opt==true)//Abre Inventario
{
if(SCUPDalt.Visible==false && Scene.PermiteMenu!=false)//If the interface is closed, open it if the scene allows it
{
Game.AbreSCUP();
}
InvWindow.AlphaColor = MakeRGBA(255, 255, 255, 0);
Game.InventoryVisible=true;

for(i=1; i<=10; i=i+2)
{
InvWindow.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
Sleep(50);
}
InvWindow.AlphaColor = MakeRGBA(255, 255, 255, 255);
}
else
{
for(i=10; i>=10; i=i-2)
{
InvWindow.AlphaColor = MakeRGBA(255, 255, 255, 25*i);
Sleep(50);
}
InvWindow.AlphaColor = MakeRGBA(255, 255, 255, 0);
Game.InventoryVisible=false;
}
}

The script runs Ok, but it is still showing in debug console, this mean that is still in memory?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Window method
« Reply #9 on: January 05, 2012, 05:30:33 PM »

The script runs Ok, but it is still showing in debug console, this mean that is still in memory?
Honestly, I don't know. It might or it might be just a display issue in the debug console and the thread isn't properly removed after it's done.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Window method
« Reply #10 on: January 06, 2012, 01:21:51 AM »

It looks like concurrency issue to me.

try something like this:

Code: WME Script
  1.  
  2. method InventoryVisible(opt)
  3. {
  4.      if (Game.VisibilityHandler) return;
  5.      Game.VisibilityHandler = true;
  6.  
  7.      // your original implementation
  8.  
  9.      Game.VisibilityHandler = false;
  10. }
  11.  

And see if this helps...
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet
 

Page created in 0.063 seconds with 21 queries.