Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Pages: [1] 2  All

Author Topic: different approach with money  (Read 10080 times)

0 Members and 1 Guest are viewing this topic.

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
different approach with money
« on: September 09, 2006, 07:51:50 PM »

i am thinking of approaching the money thing differently

Is there a way to just pick up the money item off the ground, making it disappear and just have the amount of money picked up displayed somewhere without the money item showing anymore?
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: different approach with money
« Reply #1 on: September 10, 2006, 04:07:00 PM »

Yes, absolutely. All you need to do is to keep track of the money amount in some global variable, and increase/decrease the amount when need.

global MoneyAmount;
...
MoneyAmount = MoneyAmount + 100;


The other step would be to display the amount somewhere. It will be some window, containing a static control, displaying the amount.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: different approach with money
« Reply #2 on: September 11, 2006, 04:31:46 AM »

ok, i'll go with the window thingy :-\

i have created a window and placed it in a room (i intend to use obviously always the same window in each room), but now i don't think i can work out how to grab the amount of the money and display it. I kinda figured that i should perhaps include some code that grabs the amount off items.items or maybe just include some code in items.items... (confused)... ???
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: different approach with money
« Reply #3 on: September 11, 2006, 08:19:48 AM »

It depends on how exactly you want it to look like.
Let's assume you'll use some "HUD" style window, which will be always visible on screen, displaying the money amount and possibly some other info.
So you'll create a window, something like this:

Code: [Select]
WINDOW
{
  NAME = "hud"
  X = 0
  Y = 0
  WIDTH = 800
  HEIGHT = 600
  TRANSPARENT = TRUE

  STATIC
  {
    NAME = "money"
    X = 0
    Y = 0
    WIDTH = 100
    HEIGHT = 30
    FONT = "fonts\some.font"
  }
}

Then load the window when the game starts. In game.script call something like:

Code: [Select]
global HudWindow = Game.LoadWindow("path\hud.window");
HudWindow.Visible = true;

And the most convenient way of maintaining the money display would be, IMO, adding a new Game method for changing the amount. Add this to game.script:

Code: [Select]
global MoneyAmount = 0;
method AddMoney(AddAmount)
{
  MoneyAmount = MoneyAmount + AddAmount;
 
  var MoneyDisplay = HudWindow.GetControl("money");
  MoneyDisplay.Text = "$" + ToString(MoneyAmount);
}

Now, whenever you need to change the money amount, you'll simply call something like:

Code: [Select]
Game.AddMoney(100);

or

Code: [Select]
Game.AddMoney(-50);

This call will both update the MoneyAmount variable and the HUD display.


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

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: different approach with money
« Reply #4 on: September 11, 2006, 10:03:06 AM »

thanks for your patience  ;D

I think slowly i'm starting to get it finally! lol

So... for instance if i wanted to use the inventory window instead of an HUD...is there a way to apply that code in a similar way or do i have to use a different approach?

It would be neat if the desired result would me this one:


with the black area being used to display the money. That would maximize the view for the player when the inventory is not in use and minimize the clutter.

I'm wondering because i find a lot easier to tinker with the inventory if i can, that way i don't have too many elements to worry about and keep the interface graphics to a minimum since i intend to pack the scene with a lot more sprites as soon as i am done with the money thing...

Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: different approach with money
« Reply #5 on: September 11, 2006, 10:14:55 AM »

There's nothing easier ;)
1) Add that STATIC { ... } section to your inventory window definition instead.
2) Change the code to:

Code: [Select]
global MoneyAmount = 0;
method AddMoney(AddAmount)
{
  MoneyAmount = MoneyAmount + AddAmount;
 
  var InvWindow = Game.GetInventoryWindow();
  var MoneyDisplay = InvWindow.GetControl("money");
  MoneyDisplay.Text = "$" + ToString(MoneyAmount);
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: different approach with money
« Reply #6 on: September 11, 2006, 06:47:30 PM »

mmh... it doesn't seem to work for me. All it does is the usual, it adds the money sprite in the inventory and displays the amount as any other inventory item, but nothing else happens. The picture stays the same as before :(

here is the code:

inventory.def

Code: [Select]
INVENTORY_BOX
{
  ITEM_WIDTH = 60
  ITEM_HEIGHT = 60
  SPACING = 0
  SCROLL_BY = 0
  HIDE_SELECTED = TRUE

  AREA { 91, 0, 800, 122 }
  EXCLUSIVE = FALSE
;  ALWAYS_VISIBLE = TRUE

  WINDOW
  {
    X = 0
    Y = 0
    WIDTH = 800
    HEIGHT = 50
    IMAGE = "interface\inventory.png"
  }
}
  STATIC
  {
    NAME = "money"
    X = 0
    Y = 0
    WIDTH = 100
    HEIGHT = 30
    FONT = "fonts\outline_white.font"
}


money.script

Code: [Select]
#include "scripts\base.inc"
global NPC;
global money;


////////////////////////////////////////////////////////////////////////////////
on "Take"
{



  actor.GoToObject(this);
  actor.TurnTo(this);
   
  if(!Game.IsItemTaken("money")) Game.TakeItem("money");
 
  var MoneyItem = Game.GetItem("money");
  MoneyItem.Amount = MoneyItem.Amount + 100;
  Game.AddMoney(100);
  this.Active = false;

switch(Random(1, 5))

      {
        case 1: actor.Talk("pocket the dough... don't ask."); break;
        case 2: actor.Talk("let's grab it before somebody else does..."); break;
        case 3: actor.Talk("*foot on bill*...*whistling*...now you see it... now you don't!"); break;
        case 4: actor.Talk("better in my pockets than in somebody else's"); break;
        case 5: actor.Talk("this will look nice in my collection..."); break;
      }

Game.Interactive = true;
}


game.script

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

global MoneyAmount = 0;
method AddMoney(AddAmount)
{
  MoneyAmount = MoneyAmount + AddAmount;
 
  var InvWindow = Game.GetInventoryWindow();
  var MoneyDisplay = InvWindow.GetControl("money");
  MoneyDisplay.Text = "$" + ToString(MoneyAmount);
}

// store some of the game's attributes in global variables for convenience
Keyboard = Game.Keyboard;
Scene = Game.Scene;



// load the right-click menu
global WinMenu = Game.LoadWindow("interface\menu\menu.window");
WinMenu.Visible = false;

// load the "caption" window
var win = Game.LoadWindow("interface\system\caption.window");
global WinCaption = win.GetWidget("caption");


global MenuObject = null;


// run the "daemon" script
Game.AttachScript("scripts\game_daemon.script");


// which scene to load?
Game.ChangeScene("scenes\splash\splash.scene");



////////////////////////////////////////////////////////////////////////////////
on "LeftClick"
{
  // what did we click?
  var ActObj = Game.ActiveObject;
  if(ActObj!=null)
  {
    // clicking an inventory item
if(ActObj.Type=="item" && ActObj.IsDisabled != true && Game.SelectedItem==null)
{
  Game.SelectedItem = ActObj;
  WinMenu.Visible = false;
}

    // using an inventory item on another object
    else if(Game.SelectedItem != null && Game.SelectedItem!=ActObj)
    {
      var Item = Game.SelectedItem;
      if(ActObj.CanHandleEvent(Item.Name)) ActObj.ApplyEvent(Item.Name);
      else if(Item.CanHandleEvent("default-use")) Item.ApplyEvent("default-use");
      else if(ActObj.CanHandleEvent("default-use")) ActObj.ApplyEvent("default-use");
      else actor.Talk("I can't use these things together.");
    }
    // just a simple click
    else ActObj.ApplyEvent("LeftClick");
  }
  // else propagate the LeftClick event to a scene
  else
  {
    Scene.ApplyEvent("LeftClick");
  }
}



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

on "RightClick"
{
  // if inventory item selected? deselect it
  if (Game.SelectedItem != null){
    Game.SelectedItem = null;
    return;
  }

  var ActObj = Game.ActiveObject;

  // is the righ-click menu visible? hide it
  if(WinMenu.Visible == true) WinMenu.Visible = false;
  else if(ActObj!=null)
  {
    // if the clicked object can handle any of the "verbs", display the right-click menu
    if(ActObj.CanHandleEvent("Take") || ActObj.CanHandleEvent("Talk") || ActObj.CanHandleEvent("LookAt"))
    {
      // store the clicked object in a global variable MenuObject
      MenuObject = Game.ActiveObject;
      var Caption = WinMenu.GetWidget("caption");
      Caption.Text = MenuObject.Caption;

      // adjust menu's position
      WinMenu.X = Game.MouseX - WinMenu.Width / 2;
      if(WinMenu.X < 0) WinMenu.X = 0;
      if(WinMenu.X+WinMenu.Width>Game.ScreenWidth) WinMenu.X = Game.ScreenWidth-WinMenu.Width;

      WinMenu.Y = Game.MouseY - WinMenu.Height / 2;
      if(WinMenu.Y<0) WinMenu.Y = 0;
      if(WinMenu.Y+WinMenu.Height>Game.ScreenHeight) WinMenu.Y = Game.ScreenHeight-WinMenu.Height;

      // and show the right-click menu
      WinMenu.Visible = true;

      // stop the actor from whatever he was going to do
      actor.Reset();
    }
    // no verbs supported, no menu is needed; just send the RightClick event to the object
    else ActObj.ApplyEvent("RightClick");
  }
}

////////////////////////////////////////////////////////////////////////////////
on "Keypress"
{
  // on Esc or F1 key
  if(Keyboard.KeyCode==VK_ESCAPE || Keyboard.KeyCode==VK_F1)
  {
    // load and display the main menu window
    WinCaption.Visible = false;
    var WinMainMenu = Game.LoadWindow("interface\system\mainmenu.window");
    WinMainMenu.Center();
    WinMainMenu.GoSystemExclusive();
    Game.UnloadObject(WinMainMenu);
  }
}


////////////////////////////////////////////////////////////////////////////////
on "QuitGame"
{
  // on Alt+F4 (window close)
  // load and display the quit confirmation window
  WinCaption.Visible = false;
  var WinQuit = Game.LoadWindow("interface\system\quit.window");
  WinQuit.Center();
  WinQuit.GoSystemExclusive();

  // and if the user selected Yes
  if(WinQuit.xResult)
  {
    // quit the game
    Game.QuitGame();
  }
  // otherwise just unload the quit window from memory
  else Game.UnloadObject(WinQuit);
}
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: different approach with money
« Reply #7 on: September 11, 2006, 06:53:42 PM »

The static control definition should be nested within the window defintion (the static control is a child of the window). Like this:

Code: [Select]
INVENTORY_BOX
{
  ITEM_WIDTH = 60
  ITEM_HEIGHT = 60
  SPACING = 0
  SCROLL_BY = 0
  HIDE_SELECTED = TRUE

  AREA { 91, 0, 800, 122 }
  EXCLUSIVE = FALSE
;  ALWAYS_VISIBLE = TRUE

  WINDOW
  {
    X = 0
    Y = 0
    WIDTH = 800
    HEIGHT = 50
    IMAGE = "interface\inventory.png"
   
    STATIC
    {
      NAME = "money"
      X = 0
      Y = 0
      WIDTH = 100
      HEIGHT = 30
      FONT = "fonts\outline_white.font"
    }       
  }
}

Then it should work.
Also, if you don't want the money to be displayed as an inventory item, you can get rid of all that TakeItem() stuff, and only keep these lines:

Game.AddMoney(100);
this.Active = false;
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: different approach with money
« Reply #8 on: September 11, 2006, 07:00:56 PM »

Mnemonic you are a King among men! :D

Now it works just the way i want it! :D
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: different approach with money
« Reply #9 on: September 11, 2006, 07:11:26 PM »

ARGH!

spoke too soon... :P

I got all excited about seeing some text on the inventory window that i failed to notice that instead of the money amount numbbers it simply displays

$[null]

what did i do wrong now?
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: different approach with money
« Reply #10 on: September 11, 2006, 07:34:45 PM »

Hm, it means the MoneyAmount variable has invalid value, which shouldn't happen in the code you posted. It could happen if you called Game.AddMoney() without any number, for example..
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: different approach with money
« Reply #11 on: September 11, 2006, 07:47:53 PM »

oh! i found out why!

Code: [Select]
global MoneyAmount = 0;
method AddMoney(AddAmount)
{
  MoneyAmount = MoneyAmount + AddAmount;
 
  var InvWindow = Game.GetInventoryWindow();
  var MoneyDisplay = InvWindow.GetControl("money");
  MoneyDisplay.Text = "$" + ToString(AddAmount);
}

instead of:

Code: [Select]
  MoneyDisplay.Text = "$" + ToString(MoneyAmount);
now it displays the money amount correctly :)
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: different approach with money
« Reply #12 on: September 11, 2006, 07:54:44 PM »

nope... i gotta contraddict myself again... :(

i thought it displayed the amount because it shown the number 100, but no matter how many money items i pick up the number is still 100...

 :'(
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: different approach with money
« Reply #13 on: September 11, 2006, 09:00:03 PM »

Well, maybe I'm blind, but I don't see how the variable could ever get the null value... But anyway, let's add some checks:

Code: [Select]
global MoneyAmount = 0;
method AddMoney(AddAmount)
{
  if(MoneyAmount==null) MoneyAmount = 0;
  if(AddAmount==null) AddAmount = 0;

  MoneyAmount = MoneyAmount + AddAmount;
 
  var InvWindow = Game.GetInventoryWindow();
  var MoneyDisplay = InvWindow.GetControl("money");
  MoneyDisplay.Text = "$" + ToString(MoneyAmount);
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: different approach with money
« Reply #14 on: September 11, 2006, 10:21:55 PM »

wow, now it looks like it works!

The only thing is that after my character gets killed by the guards, the game restarts with the amount set to 300 dollars, but then when i pick up the money the count restarts from 100 dollars...
« Last Edit: September 11, 2006, 10:27:45 PM by fabiobasile »
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!
Pages: [1] 2  All
 

Page created in 0.05 seconds with 20 queries.