Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Pages: [1] 2  All

Author Topic: Number in a text field in a window changes when it's not supposed to  (Read 8501 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

EDITED TYPO--
I have a "gold" system and a "health" system to add/subtract player's gold and health.

Methods are defined in game.script up at the very top:

Code: WME Script
  1. global MoneyAmount = 0;
  2. method AddMoney(AddAmount)
  3. {
  4.   if(MoneyAmount==null) MoneyAmount = 0;
  5.   if(AddAmount==null) AddAmount = 0;
  6.  
  7.   MoneyAmount = MoneyAmount + AddAmount;
  8.   global overlay = Game.LoadWindow("scenes\Kolobok\overlay.window");
  9.   var MoneyDisplay = overlay.GetControl("money");
  10.   MoneyDisplay.Text = ToString(MoneyAmount);
  11. }
  12.  
  13. global HealthAmount ="";
  14. method SubtractHealth(SubtractAmount)
  15. {
  16.   if(HealthAmount==null) HealthAmount = 100;
  17.   if(SubtractAmount==null) SubtractAmount = 0;
  18.  
  19.   HealthAmount = HealthAmount - SubtractAmount;
  20.   global overlay = Game.LoadWindow("scenes\Kolobok\overlay.window");
  21.   var HealthDisplay = overlay.GetControl("health");
  22.   HealthDisplay.Text = ToString(HealthAmount);
  23. }
  24.  

-----
On a window in a scene, I have script:

Code: WME Script
  1. #include "scripts\base.inc"
  2. var touched = 0;
  3. on "LeftClick"
  4. {
  5. if (touched==0)
  6. {Game.Msg("It is a dirty window but you find some gold.");
  7. Game.AddMoney(5);
  8. touched = 1;
  9. }
  10. else
  11. {
  12. if (touched==1)
  13. {Game.Msg("It is just a dirty window.");
  14. }
  15. }
  16. }
  17.  
  18.  

On a vase in same scene I have script:

Code: WME Script
  1. #include "scripts\base.inc"
  2. var bite = 0;
  3. on "LeftClick"
  4. {
  5. if (bite==0)
  6. {Game.Msg("Exploring the vase, you feel a sharp pain in your hand as a scorpion bites you and scuttles out of the vase.");
  7. Game.SubtractHealth(5);
  8. bite = 1;
  9. }
  10. else
  11. {
  12. if (bite==1)
  13. {Game.Msg("The vase is empty.");
  14. }
  15. }
  16. }
  17.  

It doesn't work as it should.

The display in the text box in the window starts out 0 for the gold and 100 for the health, which is fine.

If I click on the window, the gold amount changes to 5.

If I click on the vase, the health decreases by 5 to 95 which is fine BUT THE GOLD GOES BACK TO 0.
If I reload the scene to start over--
Same thing if I click on the vase first, the health decreases by 5 to 95.
Then if I click on the window, the gold increases by 5 to 5 BUT the health goes back to 100.

I think I'm passing [null] here at some point somehow when I shouldn't be. 

My spirits are down because I woefully have to redo my dialogue box using the regular response system, so any help would cheer me up.  :(
« Last Edit: February 19, 2009, 08:34:12 PM by Catacomber »
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: Number in a text field in a window changes when it's not supposed to
« Reply #1 on: December 07, 2008, 09:30:48 PM »

I'm not much of a coder,
but it seems you are loading the same window again (each time you call the methods).
May be you should load it "outside" of the methods.

Spyros

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Number in a text field in a window changes when it's not supposed to
« Reply #2 on: December 07, 2008, 10:36:09 PM »

I'll try that, thanks, Birdline.  : )
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: Number in a text field in a window changes when it's not supposed to
« Reply #3 on: December 07, 2008, 11:14:54 PM »

It works Birdline but now my overlay window is on the Title page and the Intro page where I don't want it.

:  )   Getting close.  :  )   Trying to hide the overlay window in those scenes doesn't seem to work.  I can hide the inventory window but not the overlay. 

#include "scripts\base.inc"
#include "scripts\keys.inc"

global overlay = Game.LoadWindow("scenes\Kolobok\overlay.window");

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

  MoneyAmount = MoneyAmount + AddAmount;
  global MoneyDisplay = overlay.GetControl("money");
  MoneyDisplay.Text = ToString(MoneyAmount);
}

global HealthAmount ="";
method SubtractHealth(SubtractAmount)
{
  if(HealthAmount==null) HealthAmount = 100;
  if(SubtractAmount==null) SubtractAmount = 0;

  HealthAmount = HealthAmount - SubtractAmount;
  global HealthDisplay = overlay.GetControl("health");
  HealthDisplay.Text = ToString(HealthAmount);
}
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: Number in a text field in a window changes when it's not supposed to
« Reply #4 on: December 08, 2008, 03:33:14 AM »

Is it all right to load a window in the game.script if it's going to be on top of almost every scene?

While this script works now for health and gold, I can't get rid of the window on the title scene even using the usual destroy window close etc.  If you load a window in game.script--does that mean you can never get rid of it or make it invisible? 

While this script works for me in game.script, couldn't I just have put the health method in a script file and attached it to the vase using the attach.script command?  Same for adding gold--couldn't I have put the method in a separate script file and attached it to the window or any other object? 

I tried doing that and it didn't work.

Where is the best place to declare a method? ?
« Last Edit: December 08, 2008, 03:56:56 AM by Catacomber »
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: Number in a text field in a window changes when it's not supposed to
« Reply #5 on: December 08, 2008, 08:28:55 AM »

Well, this is what I usually do with windows (HUD).
In base.inc, add
global overlay;
In game.script add
overlay = Game.LoadWindow("scenes\Kolobok\overlay.window");
overlay.Visible = false;
This way you have the window loaded during the whole game
and show/hide it when ever you want, by overlay.Visible = true;.

The methods (I think) usually are declared in the object's script, because they are part of the object.
So you should try add the methods to the window's script.
This way, you call these methods by: overlay.AddMoney(5); or overlay.SubtractHealth(20);

Of course some more experienced coders can help us here, I'm also learning WME  :D

Best regards,
Spyros

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Number in a text field in a window changes when it's not supposed to
« Reply #6 on: December 08, 2008, 03:29:23 PM »

Thank you, Spyros.  That makes sense to hide the window in game.script.  And then make it visible when it's needed.  Putting the method on the window script sounds like it will make sense too but I have to try it.

I think this is something that a lot of people who want to use Wintermute for to make an rpg type adventure game would like to nail down.  I know Wintermute wasn't made to be this sort of engine but it's so flexible I think it must be possible and that people can make some great rpg type adventure games with Wintermute---I haven't even tried using the scene as a top down world yet---but I was thinking of having cut scene battle scenes eventually between more static scenes.  GoldenSun is somewhat like this and I think it can be done.  It may take me a year to do it but was hoping to get the process done in a month which I know is not possible for me.

Thanks again for your help.
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: Number in a text field in a window changes when it's not supposed to
« Reply #7 on: December 08, 2008, 08:32:45 PM »

I'm fine with the window loading and hiding and showing and everthing it should do.

And if I have the method in game.script, everything works fine in the first scene where you get gold or lose health, but in the next scene everything reverts again to 0 and 100 as though left clicking on the objects make the gold and health values null.

I tried loading the method in the script on the window but it didn't work.  Back to square 0.  :  )

But my windows are fine now.  :  ) 
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: Number in a text field in a window changes when it's not supposed to
« Reply #8 on: December 08, 2008, 09:54:28 PM »

Modified to be clearer  :  )

Now this setup works perfectly for me Except:  When a new screen loads there is no amount in either gold or health just the picture.  The amounts update from the last transaction but the little digits don't show up next the picture unless you've had a new transaction in the current scene.  The amounts are correct but only show when you've added or subtracted something.  You can try it to see.  But everything works fine otherwise--still that's on my to solve list.  :  0  If anyone has any hints it would be most appreciated.

Window that is the hud now is called hud.
Widget in hud that displays money is called money-has a pic of gold
Widget in hud that displays health is called health—has a pic of a heart
There is nothing in the textbox to begin with either for health or money widgets.


Base.script:

global hud;


Game.script:

hud = Game.LoadWindow("scenes\Kolobok\overlay.window");
hud.Visible = false;

global MoneyAmount =0;
method AddMoney(AddAmount)
{
       if(MoneyAmount==null) MoneyAmount = 0;
       if(AddAmount==null) AddAmount = 0;
       
MoneyAmount = MoneyAmount + AddAmount;
var MoneyDisplay = hud.GetControl("money");
MoneyDisplay.Text = ToString(MoneyAmount);
}


global HealthAmount = 100;
method Subtracthealth(SubtractAmount)
{
       if(HealthAmount==null) HealthAmount = 100;
       if(SubtractAmount==null) SubtractAmount = 0;
       
HealthAmount = HealthAmount - SubtractAmount;
var HealthDisplay = hud.GetControl("health");
HealthDisplay.Text = ToString(HealthAmount);
}


In hud script



global health = this.GetControl("health");

global money = this.GetControl("money");


on object that affects your money—

#include "scripts\base.inc"
var touched = 0;
global money;
on "LeftClick"
{
if (touched==0)
{Game.Msg("It is a dirty window but you find some gold.");
Game.AddMoney(5);
touched = 1;
}
else
{
if (touched==1)
{Game.Msg("It is just a dirty window.");
}
}
}
 

on object that affects your health –

#include "scripts\base.inc"
var bite = 0;
on "LeftClick"
{
if (bite==0)
{Game.Msg("Exploring the vase, you feel a sharp pain in your hand as a scorpion bites you and scuttles out of the vase.");
Game.Subtracthealth(10);
bite = 1;
}
else
{
if (bite==1)
{Game.Msg("The vase is empty.");
}
}
}
« Last Edit: December 08, 2008, 10:00:54 PM by Catacomber »
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: Number in a text field in a window changes when it's not supposed to
« Reply #9 on: December 09, 2008, 08:38:37 AM »

Here is a simple version that works.

In base.inc:
//globals for Health-Money system
global hud;
global MoneyAmount;
global HealthAmount;
global MoneyDisplay;
global HealthDisplay;

In game.script:
//Load the health-money window
hud = Game.LoadWindow("scenes\Kolobok\overlay.window");
MoneyDisplay = overlay.GetControl("money");
HealthDisplay = overlay.GetControl("health");

In hud.script (attached to the window):
#include "scripts\base.inc"
#include "scripts\keys.inc"
MoneyAmount = 0;
method AddMoney(AddAmount)
{
  MoneyAmount = MoneyAmount + AddAmount;
  MoneyDisplay.Text = MoneyAmount;
}

HealthAmount =100;
method SubtractHealth(SubtractAmount)
{
  HealthAmount = HealthAmount - SubtractAmount;
  HealthDisplay.Text = HealthAmount;
}

In object1:
on "LeftClick"
{
  hud.SubtractHealth(10);
}

In object2:
on "LeftClick"
{
  hud.AddMoney(5);
}

This is working fine BUT I do have values in the text of the 2 static objects.
In the window:
text value for "money" is 0
text value for "health" is 100
If you don't do this, then you will see those (new) values only when clicked on object1/object2

Spyros

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Number in a text field in a window changes when it's not supposed to
« Reply #10 on: December 09, 2008, 04:35:00 PM »

Thanks, Spyros, I will try it.  I don't have the real file with me but I do have an older version. 
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: Number in a text field in a window changes when it's not supposed to
« Reply #11 on: December 10, 2008, 03:28:20 AM »

Birdline's script should work perfectly for me but it doesn't.  I don't get any script errors but when I go to left click on the object that should give me gold or take away health points, nothing happens. I've gotten this to work perfectly for me by tweaking script in different ways but I don't understand why his script doesn't work for me---it really should.  I know that his code works perfectly--because seeing my difficulty he made me a demo file and I tried his demo file and it's perfect.  : )  It works flawlessly to add gold/health and to update the displays on changing scenes. 

He's using I think the new beta and I'm not.  Would this affect whether that script would work for me?

Also I have additional code in the script connected to the window that displays the gold/health.  I have the player avatar.

This is my script on the window.

#include "scripts\base.inc"
#include "scripts\keys.inc"

MoneyAmount = 0;
method AddMoney(AddAmount)
{
  MoneyAmount = MoneyAmount + AddAmount;
  var MoneyDisplay = hud.GetControl("money");
  MoneyDisplay.Text = MoneyAmount;
}
HealthAmount =100;
method SubtractHealth(SubtractAmount)
{
  HealthAmount = HealthAmount - SubtractAmount;
  HealthDisplay = hud.GetControl("health");
  HealthDisplay.Text = HealthAmount;
}

g_GenderMale;
var Portrait = this.GetControl("portrait"); // "portrait" being the name of a static control
 
if(g_GenderMale == true) Portrait.SetImage("scenes\Kolobok\male.png");
else Portrait.SetImage("scenes\Kolobok\female.png");

Should I be using the new beta version?

Only if I move
MoneyDisplay = overlay.GetControl("money");
HealthDisplay = overlay.GetControl("health");
from Game.script
to the script attached to the Window am I able to on left click add gold or reduce health.

And only if I put
hud.GetControl("money") = MoneyAmount;
hud.GetControl("health") = HealthAmount;
in the scene.initscript for the next scene do I get the next scene to display the correct startup amounts for that scene.

I checked every comma, semicolon, word etc.  :  )  His script is right.  Why doesn't it work for me?  Just trust me that I copied his code perfectly.  :  )  Why do I have to do all that extra stuff ?  :  )

I'm not at all complaining, I'm just trying to understand.  :  ) ) )  He knows it works perfectly.  I know it should work perfectly, but it doesn't.  :  )


« Last Edit: December 10, 2008, 04:36:30 AM by Catacomber »
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: Number in a text field in a window changes when it's not supposed to
« Reply #12 on: December 10, 2008, 09:37:41 AM »

I think we made a mistake (not in the game I sent you, that is OK).
At some point you changed the name overlay with hud.
After that, one time is hud and the second time is overlay  ;D , this is a mistake.

So, decide what it should be: hud or overlay.
Then make the changes and it should work.
If not, send me the files to check.

Best regards,
Spyros

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Number in a text field in a window changes when it's not supposed to
« Reply #13 on: December 10, 2008, 03:25:13 PM »

No, Spyros, that's fine--I made all those changes.  I checked and double checked everything.  Your demo game works perfectly.  Mine only works if I tweak things.  I think it's something else and don't know if it's related to our using different versions cause I see in the WME log that you're using the newer beta version and I'm not. I'll email you an invitation to download the little demo game tonight from box.com where I store it.  I didn't put the latest version up yet.  Thanks.  If there's any code in it that's useful to you, you're welcome to it.  :  )  I appreciate your help.
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: Number in a text field in a window changes when it's not supposed to
« Reply #14 on: December 10, 2008, 04:29:04 PM »

The latest beta only deals with graphics stuff, it will not affect this basic functionality in any way.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
Pages: [1] 2  All
 

Page created in 0.065 seconds with 21 queries.