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: Increase or Decrease Gold Counter  (Read 5567 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
Increase or Decrease Gold Counter
« on: December 04, 2008, 07:48:42 PM »

I have a window with a small button containing a picture of a stack of gold and a button next to that to display the amount of gold the player has---this would change from time to time as the player finds or loses gold.

The name of the button that holds the amount (0, 1, 2, 3 etc) of gold the player has is Goldwin.

In the game.script file, I put

if(gold==null) gold = 0;

to start at 0

While I ask a lot of questions, this will taper off and I hope my questions are useful to other people.

 
in base.inc.

I put global Goldwin;

On left click on an object, where player would find a piece of gold f.e., I have script:

#include "scripts\base.inc"

on "LeftClick"
{
Game.Msg("Hello, World");
global GoldWin = Overlay.GetWidget("GoldWin");
GoldWin.Text=5;
}

The Game.Msg is just to let me know the object is reacting--no other reason.

Overlay is the name of the window containing the button GoldWin that is the Gold Counter.

The 0 doesn't change to 5 and this method wouldn't work correctly anyway because I have to add or subtract from the total as the game progresses.

Don't think GoldWin.Text = GoldWin +5;

would work as I don't think that text slot is sensitive to addition or subraction of a number there

Any solutions are appreciated.
« Last Edit: December 04, 2008, 08:19:09 PM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Spellbreaker

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Gender: Male
  • Posts: 376
    • View Profile
    • Apeiron Studios
Re: Increase or Decrease Gold Counter
« Reply #1 on: December 04, 2008, 09:08:13 PM »

Somewhere I miss the connection between GoldWin.Text and your gold variable, so whats the code of you goldwin? You have to increase your gold variable, now you manually set the text of GoldWin to "5" .
Logged

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Increase or Decrease Gold Counter
« Reply #2 on: December 04, 2008, 09:18:26 PM »

Goldwin.text is my gold variable.  I also tried adding a global gold variable to stand for the number that goes in that textbox.  And increasing that global variable but nothing happened.  Is that the right direction to go in?  I did a search in the forum and tried to model my code after what I found--one post.  :  )  That is all I could come up with.   

global Goldwin; 
global Gold;

now in base.script

and on the item you click to get the gold

#include "scripts\base.inc"

on "LeftClick"
{
         Game.Msg("Hello, World");
global GoldWin = Overlay.GetWidget("GoldWin");
var gold = GoldWin.Text;
gold +1;
}

still nothing---- : (
« Last Edit: December 04, 2008, 09:28:48 PM 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: Increase or Decrease Gold Counter
« Reply #3 on: December 04, 2008, 09:59:55 PM »

Code: [Select]
[code]This gives me some action but not what I wanted.  :  ) 

I'm using the inventory box now to store the gold counter:

On the object that should give you the gold:

[code=script]
#include "scripts\base.inc"
on "LeftClick"
{
var InvWin = Game.GetInventoryWindow();
var dd = InvWin.GetWidget("GoldWin");
dd.Text = ToString(dd);
dd=0;
dd + 1;
}


Now instead of 0 in the box it says [STATIC]--so something's going on but not what I expected.  At least it's not 0 any more.  :  )

Tried this:

Code: WME Script
  1. #include "scripts\base.inc"
  2. on "LeftClick"
  3. {
  4. var InvWin = Game.GetInventoryWindow();
  5. var dd = InvWin.GetWidget("GoldWin");
  6. dd.Text = new String(dd);
  7. dd + 1;
  8. }
  9.  

Still says [Static] ???[/code][/code]
« Last Edit: February 19, 2009, 08:27:04 PM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Spellbreaker

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Gender: Male
  • Posts: 376
    • View Profile
    • Apeiron Studios
Re: Increase or Decrease Gold Counter
« Reply #4 on: December 04, 2008, 10:23:41 PM »

Goldwin.text is my gold variable.  I also tried adding a global gold variable to stand for the number that goes in that textbox.  And increasing that global variable but nothing happened.  Is that the right direction to go in?  I did a search in the forum and tried to model my code after what I found--one post.  :  )  That is all I could come up with.   

global Goldwin; 
global Gold;

now in base.script

and on the item you click to get the gold

#include "scripts\base.inc"

on "LeftClick"
{
         Game.Msg("Hello, World");
global GoldWin = Overlay.GetWidget("GoldWin");
var gold = GoldWin.Text;
gold +1;
}

still nothing---- : (
gold and GoldWin are two different things. var gold = GoldWin.Text just *copies* GoldWin.Text to gold. So if you change gold to +1, GoldWin.Text is still the same. You have to change Goldwin.Text directly, or copy gold back to goldwin.text afterwards .
Logged

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Increase or Decrease Gold Counter
« Reply #5 on: December 04, 2008, 10:33:21 PM »

Can the "Text" part of a static control store a number and can that number be manipulated there?  Added to, subtracted from, multiplied and divided? 

I found something about manipulating a Score in the Czech part of the forum but would have to send it to one of my Czech friends to translate.  :  )

Forget what I have up top--I was rushed and it's messy and I'm starting over. 
« Last Edit: December 04, 2008, 10:36:45 PM 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: Increase or Decrease Gold Counter
« Reply #6 on: December 05, 2008, 02:46:28 AM »

Thanks, Spellbreaker.  I went back to searching the forum again, crawling through the posts on my hands and knees.  :  )  I found something useful but when I put it in my game script, I can't open the game--I get a black screen.

It's a method---called AddMoney

in game script--where Overlay is the name of my Window that holds the Static control called GoldCount that should show the amount of gold the player has.

Code: WME Script
  1.  
  2. on "AddMoney"
  3.  
  4. global MoneyAmount = 0;
  5. method AddMoney(AddAmount)
  6. {
  7.   MoneyAmount = MoneyAmount + AddAmount;
  8.  
  9.   var MoneyDisplay = Overlay.GetControl("GoldCount");
  10.   MoneyDisplay.Text = "$" + ToString(MoneyAmount);
  11. }
  12.  
  13.  

and on the object where you would get the money, you call the method--

Code: WME Script
  1. ;
  2.  
  3. on "LeftClick"
  4. {
  5.     Game.Msg("It's a dirty window but you find some gold." );
  6.           Game.AddMoney(5);
  7.     }
  8.  
 
I don't know what I'm doing wrong but I'm pretty sure this should work without blacking out my game.  :  )

This is the link where I found this possible method:

http://forum.dead-code.org/index.php?topic=1717.msg11913;topicseen#msg11913
   
« Last Edit: February 19, 2009, 08:28:06 PM 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: Increase or Decrease Gold Counter
« Reply #7 on: December 05, 2008, 04:11:35 AM »

I HAVE GOT THIS TO WORK!!!!



DOING A LITTLE CAT DANCE!!!!  ^^

IT'S BEAUTIFUL!!!!  I'M SO EXCITED!!!!

My script in game.script:

global MoneyAmount = 0;
method AddMoney(AddAmount)
{
  if(MoneyAmount==null) MoneyAmount = 0;
  if(AddAmount==null) AddAmount = 0;

  MoneyAmount = MoneyAmount + AddAmount;
  global overlay = Game.LoadWindow("scenes\Kolobok\overlay.window");
  var MoneyDisplay = overlay.GetControl("money");
  MoneyDisplay.Text = "$" + ToString(MoneyAmount);
}

Overlay is the window where the control money holds the pic of the gold and the amount.  :  )

and on the object that calls this method---a window the player is exploring with his/her greedy little hands:

on "LeftClick"
{
    Game.Msg("It's a dirty window but you find some gold." );
     Game.AddMoney(5);
    }

Of course my gold has a $ sign before it--how American in a medieval world.  But I love it.  I deeply and truly appreciate all the help I get here---I really need it but there is nothing so exciting as figuring something out yourself--albeit Mnemonic gave me the code in that post---I had to figure out how to tie it into my window.

: ) ) ) ) )

What can the player buy in my world now for $5 medieval dollar gold pieces?  Nothing.  Because I havent' put the script in yet, but I know how to do it now.  :  )  At least, I think so.  :  )  Or a sweet little monster may pick their pocket.  :  )

Since I'm afraid to take that $ sign out, I will have to explain it in the story---this world deals in Sigils -- that's the name of the gold pieces and the sign for Sigils is well,  $.  :  )
 
   
« Last Edit: December 05, 2008, 04:49:36 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: Increase or Decrease Gold Counter
« Reply #8 on: December 05, 2008, 12:11:44 PM »

There's one fatal flaw in your script. You're loading the overlay.window everytime you add some money. So you'll end up with tens or hundreds of windows loaded in memory. You should only load the overlay once.
And you can safely remove the dollar sign, it's only used for display :)
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: Increase or Decrease Gold Counter
« Reply #9 on: December 05, 2008, 03:33:35 PM »

Thanks, Mnemonic, the overlay window is always on top from the scene where it's first loaded until the end. 

How would I correct that script.

I think if I don't include:

Code: WME Script
  1. global overlay = Game.LoadWindow("scenes\Kolobok\overlay.window");
  2.   var MoneyDisplay = overlay.GetControl("money");
  3.  

I am going to get an error message in the WME log---like invalid method Get Control used with overlay. 

I am truly lousy at calling these widgets either from the scene they appear in or from a different scene--working on remedying that but right now I have trouble with it.
« Last Edit: February 19, 2009, 08:28:43 PM 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: Increase or Decrease Gold Counter
« Reply #10 on: December 05, 2008, 04:02:16 PM »

You can load the overlay somewhere in the beginning of game.script (the global overlay = Game.LoadWindow("scenes\Kolobok\overlay.window"); line). That way it will only be loaded once, as the game starts.

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: Increase or Decrease Gold Counter
« Reply #11 on: December 05, 2008, 04:49:42 PM »

Thanks, will do.
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  
 

Page created in 0.076 seconds with 21 queries.