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: Detach and Attach Script  (Read 5216 times)

0 Members and 1 Guest are viewing this topic.

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Detach and Attach Script
« on: December 06, 2008, 08:59:16 AM »

I have a window for dialogues when you left click on an npc that shows their picture, name and dialogues.

I need to update that every time you click on a new npc so it shows the new npc's name little pic and its own dialogues.

I have a window that lays out the picture and buttons but what I'm trying to do is to detach the last script attached to the window that represents the old npc's dialogue and attach the new one that is the new npc's dialogue.  Don't know if the new script has to be in the same file as the old one.

Here is what the window looks like when you left click on the original ncp:



Here is my script originally attached to the original npc that calls this dialogue window:

#include "scripts\base.inc"
global Statekolobok;
on "LeftClick"
{
  var Box = Game.LoadWindow("scenes\Kolobok\Box.window");
    Box.Visible = true;
  }


Here is my script attached to that window that I want to use forever in the game and just make little changes to it on each npc : ) :

#include "scripts\base.inc"
 on "Buttop1"
{
var a = this.GetControl("Buttop2");
a.Text = "Ready for action. Here take this key.";
var key = Scene.GetNode("key");
actor.TakeItem("key");
}

 on "Buttop3"
{
var b = this.GetControl("Buttop2");
b.Text = "Princess Vasilisa's Book of Weather Spells is missing. That could mean mischief in the wrong hands. Let me hop in your back pack and let's go.";
actor.TakeItem("kolo");
}

on "Goodbye"
{   
var e = this.GetControl("Buttop2");
e.ParentNotify = false;
e.Text = "";
  this.Close();
}

Here is my script on the new npc.  

#include "scripts\base.inc"
global Statekolobok;
on "LeftClick"
{
  var Box = Game.LoadWindow("scenes\Kolobok\Box.window");
    Box.Visible = true;
Box.DetachScript.Box.script;
Box.AttachScript.Box2.script;
  }


The Box 2 script is just the new dialogues.

I get an error message that the game can't load Box2 script.

Do I have to make a new talk window and its accompanying script for each npc?  : (
« Last Edit: December 06, 2008, 09:08:28 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Detach and Attach Script
« Reply #1 on: December 07, 2008, 04:33:42 AM »

I still need help with this or I have to load a new window for each npc.  I can't imagine this is really necessary---would really clutter up the game.   
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Detach and Attach Script
« Reply #2 on: December 07, 2008, 09:51:00 AM »

I think it would be better to use the built-in dialogue facilities provided by WME. There's the response box, which you can use for displaying the dialogue options. If you edit the response box in WindowEdit, you'll see it's just a normal window. So you can change its design to match the above image. Add a static control for the portrait.

Now you can use the WME dialogue script methods, Game.AddResponse() and Game.GetResponse() to display the response window and get a reply (see the "Scripting dialogues" chapter in the documentaion").

This will save you tremendous amounts of work compared to the way you're using now.


All extra work you need to do, is to be able to change the portrait displayed by the response box, prior to displaying the dialogue options.
To do that, attach a script to the response window, containing something like this:

Code: WME Script
  1. method SetPortrait(Filename)
  2. {
  3.   var PortraitControl = this.GetControl("portrait");
  4.   PortraitControl.SetImage(Filename);
  5. }
  6.  

Now you have added a custom method to the response window, allowing you to set the potrait from anywhere in the game.
Your actual dislaogue script would then look like this:


Code: WME Script
  1. function KolobokDialogue()
  2. {
  3.   // set kolobok's portrait
  4.   var RespWindow = Game.GetResponsesWindow();
  5.   RespWindow.SetPotrait("path\kolobok_potrait.png");
  6.  
  7.   // and create the dialogue just like in the docs
  8.   var EndBranch = false;
  9.  
  10.   while(!EndBranch) // loop until the player ends this dialogue
  11.   {
  12.     // fill in the responses
  13.     Game.AddResponse(1, "Old friend, is it you?");
  14.     Game.AddResponse(2, "Tell me about the spells.");
  15.     Game.AddResponse(3, "Goodbye.");
  16.  
  17.     // let the player choose one
  18.     var Res = Game.GetResponse();
  19.  
  20.     // let the actor say the selected response
  21.     actor.Talk(Game.LastResponse);
  22.  
  23.     // and now handle the selected one
  24.     switch(Res)
  25.     {
  26.       case 1:
  27.         // some code to handle response #1
  28.         break;
  29.  
  30.       case 2:
  31.         // some code to handle response #2
  32.         break;
  33.  
  34.       case 3:
  35.         // some code to handle response #3
  36.         EndBranch = true// response #3 exits the dialogue
  37.         break;       
  38.     }
  39.   }
  40. }
  41.  


Disclaimer: As always, the code above is totally untested and may contain errors. I'm just trying to explain the principles.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Detach and Attach Script
« Reply #3 on: December 07, 2008, 03:31:36 PM »

Thanks, Mnemonic.  I'll try it tonight. I was almost coming to the same conclusion but I don't know if it will turn out the way I'd like it to.  Thanks for the detailed explanation--that's extremely helpful.
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Detach and Attach Script
« Reply #4 on: December 08, 2008, 05:53:49 AM »

I like my dialogue box.  Am going to have to figure out a way to make it work.  :  )  Or else I will. . . use the default but will not be very happy about that for my purposes.  My box is very simple and what will go in there is very simple.  It has to work.  :  )  NOT GIVING UP!   

One of the strengths of Java from what I've been reading is it's ability to create and manipulate nice guis--so there has to be a way for me to do this.

How do you call a window in one scene from another scene?

GetWidget?  At least I could start from there.  :  )  And then see if I fail.  If I fail, I'll revert to the default method.   :  )

I tried getting the black background into the default method and it didn't show up. 

I'm not trying to be stubborn but I think there has to be a way.  If I fail, at least I tried as much as I could possibly try. 

And if I have to create a new window for each npc, if the windows are unloaded afterwards does it matter--except the wear and tear on me.  :  )   Does it increase the file size that much?
« Last Edit: December 08, 2008, 06:21:37 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Detach and Attach Script
« Reply #5 on: December 08, 2008, 06:28:35 PM »

How do you call a window in one scene from another scene?
Define what you mean by "calling a window". You can load a window into memory (Game.LoadWindow()), you can show it or hide it (.Visible = false/true) and you can destroy it (Game.UnloadObject()).

I tried getting the black background into the default method and it didn't show up. 
How? You edited the response box in WindowEdit and added a background image to the window?


Does it increase the file size that much?
Very very little.
It's not like I'm convincing you to use whatever approach, I just thought it would be easier and more flexible to script dialogues using the built-in functions. If you prefer creating a new window for every dialogue, feel free to.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Detach and Attach Script
« Reply #6 on: December 08, 2008, 08:29:48 PM »

By "calling" a window, I mean for example, to update something in the Inventory Window, you would put:

var InvWin = Game.GetInventoryWindow();
var ScoreWin = InvWin.GetWidget("score");
ScoreWin.Text = points;

If, f.e., I had a window named Cat.window  : )

what would I put instead of the above if I wanted to get access to its widget "box" ?

var Cat = Game.GetCatWindow();
var ScoreWin = Cat.GetWidget("box");
ScoreWin.Text = points;

????

I did add a black background png to the window that holds the response box but maybe it's too small or not in the right position.  I'll try again.

I know you're not trying to convince me to use the default method, you're trying to help me.  And you're wonderful.  :  )  I'd like to know how to do both--so will work with both if I can just for learning and then see which is better.  :  )

If I sound frustrated, it's because I am intrigued with your engine and have been staying up until 2 in the morning for about 2 weeks now trying to figure things out.  :  )  You're a great help I just want to do things too fast, trying this and that while going through the overwhelming amount of documentation--I have almost a shelf-load of forum printouts and sometimes reading all the forum posts, some conflict with each other and I get confused.  :  )  Not your posts--they don't conflict.
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Birdline

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • Birdline Web Site
Re: Detach and Attach Script
« Reply #7 on: December 08, 2008, 09:28:00 PM »

If, f.e., I had a window named Cat.window  : )
what would I put instead of the above if I wanted to get access to its widget "box" ?
var Cat = Game.GetCatWindow();
var ScoreWin = Cat.GetWidget("box");
ScoreWin.Text = points;

First you have to load the window:
var Cat = Game.LoadWindow("path of CatWindow");
then you can use:
var ScoreWin = Cat.GetControl("box");
ScoreWin.Text = points;

Spyros

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Detach and Attach Script
« Reply #8 on: December 08, 2008, 09:57:09 PM »

Ah, thanks, Spyros---so now I will throw out all the confusing printouts I had about that and file this one.  :  )
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Detach and Attach Script
« Reply #9 on: December 09, 2008, 04:37:50 AM »

Thanks to Mnemonic, Metamorphium and Spyros, I'm now able to use my cute, fuzzy dialogue box.  The dialogue box pops up on talking with an npc.  It's what comes in the next scene in my little demo file after the dialogue box up above with Agent K.  I will try to use the response window in the same way cause should be able to use both, but I'm happy to have this.

That's a quest of course and now I have to make a quest log that records when the quest is given and when it's done.  Runescape has a nice one that just places a line through the quest description when it's finished.  I was thinking I could just remove it.  (  ;

« Last Edit: December 09, 2008, 05:17:44 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  
 

Page created in 0.062 seconds with 21 queries.