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-08-2012, 06:24 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Question box script

Hey, i'm trying to make a question prompt that basically pops up with a question, this is in a class. So then if I want to ask the player a question I just join the NPC or weapon to the class and call the method.
I can't figure out how to get the answer back. In C# you do something like this. Here is the NPC.
PHP Code:
function onCreated(){
  
temp.qu AskQuestion("This is a title""This is a question");
  if(
qu){
    
this.chat "It's true!";
  }else{
    
this.chat "It's not true!";
  }

Here is the class.
PHP Code:
//#CLIENTSIDE
function AskQuestion(titlequestion) {
  new 
GuiWindowCtrl("QUESTION_WINDOW") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "222,99";

    
canclose false;
    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canresize true;
    
closequery false;
    
destroyonhide false;
    
text title;
    
1093;
    
646;

    new 
GuiButtonCtrl("QUESTION_YES") {
      
profile GuiBlueButtonProfile;
      
text "Yes";
      
width 116;
      
69;
    }
    new 
GuiButtonCtrl("QUESTION_NO") {
      
profile GuiBlueButtonProfile;
      
text "No";
      
width 107;
      
115;
      
69;
    }
    new 
GuiScrollCtrl("QUESTION_SCROLL") {
      
profile GuiBlueScrollProfile;
      
height 68;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 225;

      new 
GuiMLTextCtrl("QUESTION_MULTILINE") {
        
profile GuiBlueMLTextProfile;
        
height 34;
        
horizsizing "width";
        
text question;
        
width 200;
      }
    }
  }
}
function 
QUESTION_YES.onAction() {
  
QUESTION_WINDOW.destroy();
  return 
true;
}

function 
QUESTION_NO.onAction() {
  
QUESTION_WINDOW.destroy();
  return 
false;

Cheers.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #2  
Old 12-08-2012, 12:24 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
Try using scheduleevent() when they answer your question
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #3  
Old 12-08-2012, 12:35 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
So have AskQuestion(); then also have another function to get the results?
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #4  
Old 12-08-2012, 07:49 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
Exactly. I would use catchevent() to catch the button clicks on both buttons and send them to 1 method which would call the event.
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #5  
Old 12-09-2012, 12:17 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
You could probably do this, I commented the changes.

PHP Code:
function AskQuestion(titlequestion) {
  
this.ans false;
  
  new 
GuiWindowCtrl("QUESTION_WINDOW") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "222,99";

    
canclose false;
    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canresize true;
    
closequery false;
    
destroyonhide false;
    
    
// added visible = true so it shows for new messages
    
visible true;
    
text title;
    
1093;
    
646;

    new 
GuiButtonCtrl("QUESTION_YES") {
      
profile GuiBlueButtonProfile;
      
text "Yes";
      
width 116;
      
69;
      
      
// catch the buttonclick event and send it to onButtonClick
      
thiso.catchEvent(this"onAction""onButtonClick");
    }
    new 
GuiButtonCtrl("QUESTION_NO") {
      
profile GuiBlueButtonProfile;
      
text "No";
      
width 107;
      
115;
      
69;
      
      
// catching the buttonclick event and send it to onButtonClick
      
thiso.catchEvent(this"onAction""onButtonClick");
    }
    new 
GuiScrollCtrl("QUESTION_SCROLL") {
      
profile GuiBlueScrollProfile;
      
height 68;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 225;

      new 
GuiMLTextCtrl("QUESTION_MULTILINE") {
        
profile GuiBlueMLTextProfile;
        
height 34;
        
horizsizing "width";
        
text question;
        
width 200;
      }
    }
  }
  
  
// wait until the window is hidden 
  
waitfor(QUESTION_WINDOW"onHide");

  return 
this.ans;
}

function 
onButtonClick(obj) {
  
this.ans obj.text != "No";
  
QUESTION_WINDOW.hide();

Seems like déjà vu.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #6  
Old 12-09-2012, 11:26 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Cheers Tig, wasn't even aware Graal had a waitfor method.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
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:23 PM.


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