Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: Making a method for showing a window  (Read 10424 times)

0 Members and 1 Guest are viewing this topic.

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Making a method for showing a window
« on: March 08, 2004, 09:37:10 PM »

Sorry for posting so many messages today, but I'm trying hard to learn WME very fast.

I'm trying to do the following...
My game is going to have "narrators" text like in Gabriel Knight. I want it to run at the bottom of the screen.

Basically I want to be able to stick something like
Code: [Select]
Narrator("I felt very strange that day. Like something was about to happen...");...inside my scripts. This custom function should be available in my whole game, not just one scene.

Okay, so I probably need to make a window for that. And I need to make a method, right?

Could you guys give one or two pointers as to how to set this up in terms of structure? I think I can handle making the individual parts, but I'm a bit lost how to set up the grand scheme ;)

Still learning, still learning ...

Thanks guys.
Logged

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re:Making a method for showing a window
« Reply #1 on: March 08, 2004, 09:40:33 PM »

I guess I need to make something like:
Code: [Select]
TEXT = "+ parameter"I suppose I want to know how to send that parameter to the window? Am I making sense? :)

How does the structure work? I'm guessing...

- make window template
- make a narrator.script with a method that makes a window using the window template, and inserts a parameter in the text field
- make an include at some high-level file so that the method is available everywhere ...

please help me along  :-X :)
« Last Edit: March 08, 2004, 09:43:44 PM by Marek »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:Making a method for showing a window
« Reply #2 on: March 09, 2004, 09:41:17 AM »

Yes, that's one of the possible ways and probably the best one :)

1) create a window with one static control which will contain the narrator text

Code: [Select]
WINDOW
{
  X = 0
  Y = 500
  WIDTH = 800
  HEIGHT = 100
 
  SCRIPT = "path\NarratorWin.script"
  STATIC
  {
    NAME = "text"
    X = 0
    Y = 0
    WIDTH = 800
    HEIGHT = 100
    FONT = "fonts\MyCoolFont.font"
    TEXT_ALIGN = "center"
  }
}

Of course, you need to change the position and size appropriately.


2) Edit the logic of the window, i.e. the attached NarratorWin.script

We will add a method to display the text, so that the method is available from the outside.

Code: [Select]
method DisplayText(Text, Duration)
{
  // query the static control
  var St = this.GetControl("text");
 
  // set the text and wait
  St.Text = Text;
  Sleep(Duration);
 
  // hide the text after the "Duration" period has passed
  St.Text = "";
}


3) You need to load the narrator window at startup, the best thing would be to load it somewhere in the game.script. We will store the window in a global variable so that it's available everywhere.

Code: [Select]
global WinNarrator = Game.LoadWindow("path\Narrator.window");

4) Now, whenever you need to display the narrator text, just call the DisplayText of the WinNarrator.

Code: [Select]
global WinNarrator;
WinNarrator.DisplayText("Balh blah", 2000);

You may want to add the global WinNarrator; line to the base.inc file, so that it's (by default) included in all the scripts so that you don't need to decalre it exlicitly.

If you want to achieve the Gabriel Knight effect, you can also set the game viewport a bit smaller than the game's resolution to get the black stripe at the bottom of the screen. The viewport can be set in ProjectMan.

(Note: I didn't test the code so there may be some mistakes, but you get the idea)
« Last Edit: March 09, 2004, 10:01:21 AM by Mnemonic »
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

MMR

  • Global Moderator
  • Frequent poster
  • *
  • Karma: 3
  • Offline Offline
  • Gender: Male
  • Posts: 349
  • http://mmrdeveloper.wordpress.com/
    • View Profile
    • TinyWME
Re:Making a method for showing a window
« Reply #3 on: March 09, 2004, 09:56:57 AM »

I think there's a mistake in the first piece of code. In where you "hide" the Text, instead of

Code: [Select]
St.Text = Text;

you should put
 
Code: [Select]
St.Text = "";
 ::)
« Last Edit: March 09, 2004, 09:58:00 AM by MMR »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:Making a method for showing a window
« Reply #4 on: March 09, 2004, 10:01:48 AM »

Oops! Thanks, corrected.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re:Making a method for showing a window
« Reply #5 on: March 09, 2004, 03:33:12 PM »

Thanks for the quick tutorial. I was on the right path but I couldn't have solved it without your help.
« Last Edit: March 09, 2004, 03:33:24 PM by Marek »
Logged

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re:Making a method for showing a window
« Reply #6 on: March 11, 2004, 03:48:29 PM »

Okay, so I spoke to soon. I finally implemented this today and it's not working :'(

I checked the paths, syntax, etc. and it all adds up I think. The WME log doesn't show any errors.

This is my window:
Code: [Select]
WINDOW
{
  X = 0
  Y = 500
  WIDTH = 800
  HEIGHT = 100
  TRANSPARENT = TRUE
  VISIBLE = TRUE

  SCRIPT = "scripts\narrator.script"
  STATIC
  {
    NAME = "text"
    X = 0
    Y = 0
    WIDTH = 800
    HEIGHT = 10
    FONT = "fonts\outline_white.font"
    TEXT_ALIGN = "center"
  }
}

Transparent and visible probably don't have to be in there but I was just trying.

This is my script for the window:

Code: [Select]
#include "scripts\base.inc"
#include "scripts\keys.inc"

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

method DisplayText(Text, Duration)
{
  // query the static control
  var St = this.GetControl("text");
 
  // set the text and wait
  St.Text = Text;
  Sleep(Duration);
 
  // hide the text after the "Duration" period has passed
  St.Text = "";
}

And this is what I put at the end of a scene_init:

Code: [Select]
global WinNarrator;
WinNarrator.DisplayText("Meanwhile...", 2000);

So what am I doing wrong? :)
« Last Edit: March 11, 2004, 03:48:51 PM by Marek »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:Making a method for showing a window
« Reply #7 on: March 11, 2004, 04:03:19 PM »

Is HEIGHT = 10 correct? Shouldn't it be 100? If you really have the height of 10, the text probably won't fit into the static control.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re:Making a method for showing a window
« Reply #8 on: March 11, 2004, 04:50:19 PM »

You're right. Muchos gracias!

If I move global WinNarrator; to base.inc, the game won't start though (just a black screen). Any ideas?
« Last Edit: March 11, 2004, 04:52:31 PM by Marek »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:Making a method for showing a window
« Reply #9 on: March 11, 2004, 06:04:05 PM »

You're right. Muchos gracias!

If I move global WinNarrator; to base.inc, the game won't start though (just a black screen). Any ideas?

Hm, it should work. Check the log file (wme.log), now it will say something.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re:Making a method for showing a window
« Reply #10 on: March 11, 2004, 06:18:38 PM »

Code: [Select]
18:17: Compiling script 'scripts\game.script'...
18:17:   Error@line 5: Duplicate declaration of variable 'WinNarrator'

This is the line from game.script:
Code: [Select]
// load the method for showing narrator text
global WinNarrator = Game.LoadWindow("scripts\narrator.window");

Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:Making a method for showing a window
« Reply #11 on: March 11, 2004, 06:32:47 PM »

So, you have "global WinNarrator" in both game.script and base.inc? That way the variable gets declared twice. Change the line in game.script to:

WinNarrator = Game.LoadWindow("scripts\narrator.window");

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

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re:Making a method for showing a window
« Reply #12 on: March 11, 2004, 06:38:24 PM »

I guess I got confused earlier on. :)
Logged

Marek

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re:Making a method for showing a window
« Reply #13 on: March 12, 2004, 04:38:57 PM »

I've got another follow-up. I want to make the narrator windows skippable like normal talk text.

I thought adding this to narrator.script would do the trick:
Code: [Select]
on "LeftClick"
{
  self.Close();
}
... but it doesn't.
What's the correct way?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:Making a method for showing a window
« Reply #14 on: March 12, 2004, 05:46:30 PM »

Change the dimensions of the window to cover the entire screen. Also remove the TRANSPARENT = TRUE line, so that the window can be clicked.

You will also have to modify the script to show/hide the window, instead of just hiding the text.
Simply add
this.Visible = true;
to the beginning and
this.Visible = false;

to the end of the DisplayText method.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.042 seconds with 19 queries.