Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-13-2011, 08:08 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Confirmation box troubles

HTML Code:
function WarpAIS_Button.onAction(){

confirm("WarptoAIS");
if(this.flag ==1){
this.chat = "test";
}else if (this.flag == 0)
{
this.chat = "no";
}
}



function confirm(action){
this.flag = 0;
	new GuiWindowCtrl("ConfirmationBox"){
		profile = "GuiBlueWindowProfile";
		width = 131;
		height = 110;
		x = player.x;
		y = player.y;
		text = "Confirmation";
		canMaximize=false;
		canMinimize=false;
		destroyonhide=true;
		canresize = false;

	new GuiTextCtrl("AlertConfirm_l") {
	  profile = GuiBlueTextProfile;
	  x = 11;
	  y = 27;
	  height = 15;
	  width = 130;
	  text = "Proceed with:";
	}

	new GuiTextCtrl("AlertConfirm_l_action") {
	  profile = GuiBlueTextProfile;
	  x = 30;
	  y = 42;
	  height = 15;
	  width = 130;
	  text = action;
	}

	new GuiButtonCtrl("cYes_Button") {
	   profile = GuiBlueButtonProfile;
	   x = 11;
	   y = 67;
	   width = 50;
	   height = 30;
	   text = "Yes";
	 }

	new GuiButtonCtrl("cNo_Button") {
	   profile = GuiBlueButtonProfile;
	   x = 71;
	   y = 67;
	   width = 50;
	   height = 30;
	   text = "No";
	 }

	}
}

function cYes_Button.onAction()
{
ConfirmationBox.destroy();
this.flag = 1;
}
function cNo_Button.onAction()
{
ConfirmationBox.destroy();
this.flag = 0;
}
Here is a snippet of a script I created. The problem is, when I click the WarptoAIS button, yes the confirmation box does popup, but the value that the WarpAIS_Button.onAction() is always false because when the confirm box is created.. How can I make a function to confirm an action before performing it?

in short...
Action --> Confirm --> If true, do action
Reply With Quote
  #2  
Old 12-13-2011, 09:54 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
You should style the code first. Can often help to find errors.

Now what you could do is (as far as I understood it correctly):
PHP Code:
function ButtonBeenPressed.onAction() {
  
DoEvent();
  
//For example: you pressed the confirmation button (you need to change the name on this event for that
}

function 
DoEvent() {
  
player.chat "Hell jea I just pressed that wonderful button.";
  
//here you can do your stuff, you want the player to do after confirming

__________________
MEEP!
Reply With Quote
  #3  
Old 12-13-2011, 09:58 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
It is of utter importance that you style your code before posting it. If you don't know how please learn and use my GS2 Style in the mean time: http://fp4.ca/gs2beautifier

Sounds like you want to create a 'confirm' dialog window. You need to use waitfor to accomplish that. I explain in my guide below:

http://forums.graalonline.com/forums...hp?t=134261899
__________________
Quote:
Reply With Quote
  #4  
Old 12-14-2011, 12:03 AM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Quote:
Originally Posted by fowlplay4 View Post
It is of utter importance that you style your code before posting it. If you don't know how please learn and use my GS2 Style in the mean time: http://fp4.ca/gs2beautifier

Sounds like you want to create a 'confirm' dialog window. You need to use waitfor to accomplish that. I explain in my guide below:

http://forums.graalonline.com/forums...hp?t=134261899
Perfect. Problem solved, thanks.
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #5  
Old 12-14-2011, 06:34 AM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Actually, no problem not solved yet...

PHP Code:
function WarptoAIS_Button.onAction() {
    if (
confirm("Warp to AIS")) {
        
this.chat "Works?";
    }
}

function 
confirm(action) {
    new 
GuiWindowCtrl("ConfirmationBox") {
        
profile "GuiBlueWindowProfile";
        
width 131;
        
height 110;
        
player.x;
        
player.y;
        
text "Confirmation";
        
canMaximize false;
        
canMinimize false;
        
destroyonhide true;
        
canresize false;
        
this.returnvalue false;
        new 
GuiTextCtrl("AlertConfirm_l") {
            
profile GuiBlueTextProfile;
            
11;
            
27;
            
height 15;
            
width 130;
            
text "Proceed with:";
        }
        new 
GuiTextCtrl("AlertConfirm_l_action") {
            
profile GuiBlueTextProfile;
            
30;
            
42;
            
height 15;
            
width 130;
            
text action;
        }
        new 
GuiButtonCtrl("cYes_Button") {
            
profile GuiBlueButtonProfile;
            
11;
            
67;
            
width 50;
            
height 30;
            
text "Yes";
            
thiso.catchevent(this.name"onAction""onReplied");
        }
        new 
GuiButtonCtrl("cNo_Button") {
            
profile GuiBlueButtonProfile;
            
71;
            
67;
            
width 50;
            
height 30;
            
text "No";
            
thiso.catchevent(this.name"onAction""onReplied");
        }
    }
    
waitfor(this"AnsweredDialog"3600);
    return 
ConfirmationBox.returnvalue;
}

function 
onReplied(obj) {
    
ConfirmationBox.returnvalue = (obj.text == "Yes" true false);
    
ConfirmationBox.hide();
    
this.trigger("AnsweredDialog""");

The confirmation box does popup and it does hide when I click yes or no, but it wont return a value, If I take off the hide() then it does return the value...
__________________
http://i.imgur.com/OOJbW.jpg

Last edited by BlueMelon; 12-14-2011 at 09:04 PM..
Reply With Quote
  #6  
Old 12-14-2011, 06:41 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by BlueMelon View Post
The confirmation box does popup and it does hide when I click yes or no, but it wont return a value, If I take off the hide() then it does return the value...
It's been said twice before but please do a better job of styling your code.

Try setting visible to false instead of using hide().

If that doesn't work you can get around that by removing the hide() code in the onReplied event and doing this instead:

PHP Code:
// other code
    
waitfor(this,"AnsweredDialog",3600);
    
temp.value ConfirmationBox.returnvalue;
    
ConfirmationBox.hide();
    return 
temp.value;
// other code 
__________________
Quote:
Reply With Quote
  #7  
Old 12-14-2011, 07:43 AM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Quote:
Originally Posted by fowlplay4 View Post
It's been said twice before but please do a better job of styling your code.

Try setting visible to false instead of using hide().

If that doesn't work you can get around that by removing the hide() code in the onReplied event and doing this instead:

PHP Code:
// other code
    
waitfor(this,"AnsweredDialog",3600);
    
temp.value ConfirmationBox.returnvalue;
    
ConfirmationBox.hide();
    return 
temp.value;
// other code 

My code is styled? I style it like I do in C++... standardized style.
(Except for the last function in my latest post)
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #8  
Old 12-14-2011, 07:30 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by BlueMelon View Post
My code is styled? I style it like I do in C++... standardized style.
I see a clusterfudge of 1TBS and Allman styles.

We use 1TBS, 2 (hard) space tabstop or you will be eaten alive.

Also, there is no standard style for C++ and I am not gonna open that bucket of worms. But 1TBS 4 lyfe.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #9  
Old 12-14-2011, 08:52 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Quote:
Originally Posted by Tolnaftate2004 View Post
I see a clusterfudge of 1TBS and Allman styles.

We use 1TBS, 2 (hard) space tabstop or you will be eaten alive.

Also, there is no standard style for C++ and I am not gonna open that bucket of worms. But 1TBS 4 lyfe.
x=1;
and
x = 1;

Same thing. And if anyone really gets confused by that... I don't even know what to say.
__________________
http://i.imgur.com/OOJbW.jpg

Last edited by BlueMelon; 12-14-2011 at 09:04 PM..
Reply With Quote
  #10  
Old 12-14-2011, 11:45 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by BlueMelon View Post
x=1;
and
x = 1;

Same thing. And if anyone really gets confused by that... I don't even know what to say.
That is not even close to what we're talking about.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #11  
Old 12-15-2011, 01:06 AM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Quote:
Originally Posted by Tolnaftate2004 View Post
That is not even close to what we're talking about.
Then I have no clue what your saying.

If you can't read my script (not the first post the latest post, cause first post is C&P error)
I would reconsider your ability in programming.
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #12  
Old 12-15-2011, 02:53 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by BlueMelon View Post
not the first post the latest post, cause first post is C&P error
Ah....
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/

Last edited by Tolnaftate2004; 12-15-2011 at 03:10 AM..
Reply With Quote
  #13  
Old 12-15-2011, 10:04 PM
iBeatz iBeatz is offline
Kavan
iBeatz's Avatar
Join Date: Dec 2010
Location: Northern Ireland, UK
Posts: 154
iBeatz will become famous soon enough
Send a message via Yahoo to iBeatz
Quote:
Originally Posted by BlueMelon View Post
Then I have no clue what your saying.

If you can't read my script (not the first post the latest post, cause first post is C&P error)
I would reconsider your ability in programming.
That's not obnoxious at all...
I think you'd be better just listening to the advice given to you by people who know what they're talking about.
__________________

Intelligence without ambition is like a bird without wings.

Reply With Quote
  #14  
Old 12-15-2011, 10:06 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Styling helps with the debug process and makes the code look neat and readable overall. I didn't style my code, but I started having issues reading long lines of code and I often got confused. Now, I do it automatically. It doesn't take long to get to grips with it and it makes it more readable to people trying to help you (like on this occasion)

If you really want the help, then you should really follow advice from more experienced coders. Take fowlplay for instance. He's been coding for a very long time now. If he says that styling your code will help, then it probably will help. I had issues reading that thing.
__________________
Reply With Quote
  #15  
Old 12-15-2011, 10:18 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Quote:
Originally Posted by iBeatz View Post
That's not obnoxious at all...
I think you'd be better just listening to the advice given to you by people who know what they're talking about.
Yea it was a little rude, but when people comment on my programming I get iffy.

I've programming in C++ and python for over 3 years, I know what I'm talking about.

I am also well capable of "styling" my code and finding errors on my own its just that there is no GScript doc excepting Graal Bible and Wiki, but even those don't have every single function you can use.

I appreciate the help I got, no further replys should be made.

Quote:
Originally Posted by Emera View Post
Styling helps with the debug process and makes the code look neat and readable overall. I didn't style my code, but I started having issues reading long lines of code and I often got confused. Now, I do it automatically. It doesn't take long to get to grips with it and it makes it more readable to people trying to help you (like on this occasion)

If you really want the help, then you should really follow advice from more experienced coders. Take fowlplay for instance. He's been coding for a very long time now. If he says that styling your code will help, then it probably will help. I had issues reading that thing.
That is because you didn't take the time to scroll down and read that it was a copy/paste error with the [html] tags, I don't actually code like that >.>
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:05 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.