Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Confirmation box troubles (https://forums.graalonline.com/forums/showthread.php?t=134265244)

BlueMelon 12-13-2011 08:08 PM

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

callimuc 12-13-2011 09:54 PM

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



fowlplay4 12-13-2011 09:58 PM

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

BlueMelon 12-14-2011 12:03 AM

Quote:

Originally Posted by fowlplay4 (Post 1677673)
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.

BlueMelon 12-14-2011 06:34 AM

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...

fowlplay4 12-14-2011 06:41 AM

Quote:

Originally Posted by BlueMelon (Post 1677757)
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 


BlueMelon 12-14-2011 07:43 AM

Quote:

Originally Posted by fowlplay4 (Post 1677760)
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)

Tolnaftate2004 12-14-2011 07:30 PM

Quote:

Originally Posted by BlueMelon (Post 1677772)
My code is styled? I style it like I do in C++... standardized style.

I see a clusterfudge of 1TBS and Allman styles. :confused:

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.

BlueMelon 12-14-2011 08:52 PM

Quote:

Originally Posted by Tolnaftate2004 (Post 1677838)
I see a clusterfudge of 1TBS and Allman styles. :confused:

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.

Tolnaftate2004 12-14-2011 11:45 PM

Quote:

Originally Posted by BlueMelon (Post 1677843)
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.

BlueMelon 12-15-2011 01:06 AM

Quote:

Originally Posted by Tolnaftate2004 (Post 1677856)
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.

Tolnaftate2004 12-15-2011 02:53 AM

Quote:

Originally Posted by BlueMelon (Post 1677862)
not the first post the latest post, cause first post is C&P error

Ah....

iBeatz 12-15-2011 10:04 PM

Quote:

Originally Posted by BlueMelon (Post 1677862)
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.

Emera 12-15-2011 10:06 PM

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.

BlueMelon 12-15-2011 10:18 PM

Quote:

Originally Posted by iBeatz (Post 1677974)
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 (Post 1677975)
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 >.>

Emera 12-15-2011 10:20 PM

Quote:

Originally Posted by BlueMelon (Post 1677976)
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.

Python and C++ aren't the same as GS2 and different programming languages have different coding methods. If you've been coding for "3 years" you should know that.

BlueMelon 12-15-2011 11:09 PM

Quote:

Originally Posted by Emera (Post 1677978)
Python and C++ aren't the same as GS2 and different programming languages have different coding methods. If you've been coding for "3 years" you should know that.

GScript is like a fusion of Java and C++. Event based with OOP.

There is no "correct" method, its all in the logic you use. If you can read it clearly, and it makes sense to others, there is no need to say "YOUR MISSING A SPACE HERE, OH AND HERE TO.".

cbk1994 12-15-2011 11:22 PM

Quote:

Originally Posted by BlueMelon (Post 1677995)
If you can read it clearly, and it makes sense to others, there is no need to say "YOUR MISSING A SPACE HERE, OH AND HERE TO.".

Yes, there is. Consistency is important.

Tolnaftate2004 12-15-2011 11:22 PM

Quote:

Originally Posted by BlueMelon (Post 1677995)
There is no "correct" method, its all in the logic you use. If you can read it clearly, and it makes sense to others, there is no need to say "YOUR MISSING A SPACE HERE, OH AND HERE TO.".

If you ever work in industry or contribute to an open source project, you'll quickly learn that this is generally not true.

e: by seconds!!!

BlueMelon 12-15-2011 11:33 PM

Quote:

Originally Posted by cbk1994 (Post 1677997)
Yes, there is. Consistency is important.


if(bool){
and
if ( bool ) {

So your saying one is better then the other?

Both are the same and are easily readable.

fowlplay4 12-15-2011 11:54 PM

I just said it twice and made it bold because your post (before you edited it) wasn't styled all the way through.

cbk1994 12-16-2011 02:10 AM

Quote:

Originally Posted by BlueMelon (Post 1678000)
if(bool){
and
if ( bool ) {

So your saying one is better then the other?

Both are the same and are easily readable.

The first is better because it's consistent with the vast majority of the GScript community (if there was a space after 'if' and ')'). The second is acceptable, however, as long as every other script on the server follows the same formatting rules for consistency. The only thing worse than bad styling is bad and good styling in the same script.

Tolnaftate2004 12-16-2011 02:44 AM

Quote:

Originally Posted by BlueMelon (Post 1677757)
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...

You can do:

PHP Code:

  // snip
  
while (!waitfor(this.name"AnsweredDialog"));
  return 
params[0];
}

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



BlueMelon 12-16-2011 06:58 AM

Quote:

Originally Posted by Tolnaftate2004 (Post 1678041)
You can do:

PHP Code:

  // snip
  
while (!waitfor(this.name"AnsweredDialog"));
  return 
params[0];
}

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



This has already been said, but thank you.

Questions are answered, thanks everyone.

Tolnaftate2004 12-16-2011 09:42 AM

Quote:

Originally Posted by BlueMelon (Post 1678099)
This has already been said, but thank you.

Questions are answered, thanks everyone.

Actually, to add to that, the use of ternary operator in your code is redundant.

BlueMelon 12-16-2011 09:02 PM

Quote:

Originally Posted by Tolnaftate2004 (Post 1678112)
Actually, to add to that, the use of ternary operator in your code is redundant.

Please tell me where they are redundant so I can try and improve on that.

Tolnaftate2004 12-16-2011 09:05 PM

Quote:

Originally Posted by BlueMelon (Post 1678178)
Please tell me where they are redundant so I can try and improve on that.

PHP Code:

 x == true false 

is better expressed as simply
PHP Code:

 x == 



All times are GMT +2. The time now is 02:32 AM.

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