Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: Endrit on February 21, 2012, 05:59:53 PM

Title: Create a button by script !?!?
Post by: Endrit on February 21, 2012, 05:59:53 PM
Hi guys ,
I have a problem !
In a window i have a button and when i press this one i'd like that it create another button !
I have this code but it doesn't function ;

Code: WME Script
  1. on "button1" {
  2. var button2 = CreateButton("button2");
  3.  
  4. }
  5.  

please help me ! Thanks to all !
Title: Re: Create a button by script !?!?
Post by: metamorphium on February 21, 2012, 09:12:39 PM
so even if you do something like the following it doesn't work? Does the "Sanity check!" message display?

Code: WME Script
  1.  
  2. on "button1" {
  3.  
  4. Game.Msg("Sanity check!");
  5.  
  6. var button2 = this.CreateButton("button2");
  7. button2.X = this.Width * 0.5;
  8. button2.Y = this.Height * 0.5;
  9.  
  10. button2.Width = 200;
  11. button2.Height = 100;
  12.  
  13. button2.Text = "I am a button";
  14. button2.Visible = true;
  15.  
  16. }
  17.  
  18.  

Title: Re: Create a button by script !?!?
Post by: Endrit on February 23, 2012, 03:40:45 PM
so even if you do something like the following it doesn't work? Does the "Sanity check!" message display?

Code: WME Script
  1.  
  2. on "button1" {
  3.  
  4. Game.Msg("Sanity check!");
  5.  
  6. var button2 = this.CreateButton("button2");
  7. button2.X = this.Width * 0.5;
  8. button2.Y = this.Height * 0.5;
  9.  
  10. button2.Width = 200;
  11. button2.Height = 100;
  12.  
  13. button2.Text = "I am a button";
  14. button2.Visible = true;
  15.  
  16. }
  17.  
  18.  

Thank you !!! :)
I really didn't think to make it visible :| ! ::rock
Title: Re: Create a button by script !?!?
Post by: Endrit on February 25, 2012, 07:54:44 PM
so even if you do something like the following it doesn't work? Does the "Sanity check!" message display?

Code: WME Script
  1.  
  2. on "button1" {
  3.  
  4. Game.Msg("Sanity check!");
  5.  
  6. var button2 = this.CreateButton("button2");
  7. button2.X = this.Width * 0.5;
  8. button2.Y = this.Height * 0.5;
  9.  
  10. button2.Width = 200;
  11. button2.Height = 100;
  12.  
  13. button2.Text = "I am a button";
  14. button2.Visible = true;
  15.  
  16. }
  17.  
  18.  

well i'd like to delete it but it doesn't function  ::slug ::slug!
 the code is now :
Code: WME Script
  1.  
  2. on "button1" {
  3.  
  4. Game.Msg("Sanity check!");
  5.  
  6. var button2 = this.CreateButton("button2");
  7. button2.X = this.Width * 0.5;
  8. button2.Y = this.Height * 0.5;
  9.  
  10. button2.Width = 200;
  11. button2.Height = 100;
  12.  
  13. button2.Text = "I am a button";
  14. button2.Visible = true;
  15.  
  16. }
  17.  
  18. on "button2" {
  19.  
  20. Game.Msg("Sanity check!");
  21.  
  22. var delete = this.DeleteButton("buttno2");
  23.  
  24. }
  25.  
i added the game message to check it but nothing !
 ::slug ::slug ::slug ::slug ::slug ::slug ::slug
Title: Re: Create a button by script !?!?
Post by: metamorphium on February 25, 2012, 09:21:12 PM
if this code is actual, you have a few problems:

var delete = this.DeleteButton("buttno2"); //note a typo (buttno)

I am not sure you can delete button by name, correct way is:

Code: WME Script
  1.  
  2. var btn = this.GetControl("button2");
  3. this.DeleteButton(btn);
  4.  
  5.  

 
Title: Re: Create a button by script !?!?
Post by: Mnemonic on February 25, 2012, 10:24:49 PM
Also when creating the button, set its ParentNotify property to true, so that it sends events to the window.

Code: WME Script
  1. button2.ParentNotify = true;
  2.  
Title: Re: Create a button by script !?!?
Post by: Endrit on February 25, 2012, 10:30:05 PM
if this code is actual, you have a few problems:

var delete = this.DeleteButton("buttno2"); //note a typo (buttno)

I am not sure you can delete button by name, correct way is:

Code: WME Script
  1.  
  2. var btn = this.GetControl("button2");
  3. this.DeleteButton(btn);
  4.  
  5.  


In this way it function !
But I tried to to delete it by clicking on it the code is the next and it doesn't function :(  ::slug ::slug ::slug ::slug
(I know that I'm being boring but i need your help metamorphium ! Sorry :( ) 



Code: WME Script
  1. var c_map= this.CreateButton ("Maps");
  2. c_map.Name = "Maps";
  3. c_map.X = 20 ;
  4. c_map.Y = 40 ;
  5. c_map.Width = 35;
  6. c_map.Height = 40 ;
  7. c_map.SetImage("interface\omega\Maps0001.png");
  8. c_map.SetHoverImage ("interface\omega\Maps0002.png") ;
  9. c_map.Visible = true ;
  10. var btn = this.GetControl("Maps");
  11.  
  12. on "Maps" {
  13. this.DeleteButton (btn);
  14. }
  15.  
  16.  
Title: Re: Create a button by script !?!?
Post by: Mnemonic on February 26, 2012, 10:17:06 AM
See my post above.
Title: Re: Create a button by script !?!?
Post by: Endrit on February 26, 2012, 10:46:02 AM
Thank  you Mnemonic !