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


All times are GMT +2. The time now is 11:38 PM.

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