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 07-20-2008, 07:32 PM
The_Kez The_Kez is offline
N-Pulse Asst. Manager
The_Kez's Avatar
Join Date: Dec 2007
Posts: 106
The_Kez is on a distinguished road
Send a message via MSN to The_Kez
Few questions

I have just a couple questions (mostly dealing with GUI stuff) and I don't really want to make three different topics, so I'll just do it all here.

First of all, about using onAction to check if the return key has been pressed in a text edit control, (I've decided to script a sort of instant-messaging thing just to test GUI functionalities) I have a dynamic GUI:

PHP Code:
    new GuiScrollCtrl"Chat_MultiLineEdit1_Scroll$" acct ) {
      
//scroll stuff
      
      
new GuiMLTextEditCtrl"Chat_MultiLineEdit1$" acct ) {
        
//textedit stuff
        
thiso.catcheventthis.name "onAction" "onSendMessage" );
      }
    } 
That should trigger this Event:

PHP Code:
function onSendMessageobj ) {
  
temp.obj.tokenize("$")[1];
  
temp.= ( "Chat_MultiLineEdit1$" temp.).text;
  if ( 
temp.b.starts("/") ) {
    if ( 
temp.== "/clear" ) {
      ( 
"Chat_MultiLineEdit1$" temp.).text "";
      ( 
"Chat_MultiLine1$" temp.).text "<u>Chat history with " temp.@"</u>";
    }
    else ( 
"Chat_MultiLineEdit1$" temp.).text "Unknown command.";
  }
  else {
    if ( 
temp.b.pos("<") == -) {
      if ( 
temp.b.length() >= ) {
        ( 
"Chat_MultiLineEdit1$" temp.).text "";
        ( 
"Chat_MultiLine1$" temp.).text @= "<br><b>" player.account ":</b> " temp.b;
        ( 
"Chat_MultiLine1$" temp.).scrolltobottom();
        
triggerServer("gui",name,"SendMessage",temp.a,player.account,temp.b);
      }
    }
    else ( 
"Chat_MultiLineEdit1$" temp.).text "HTML tags are not allowed.";
  }

I have a 'send' button that uses catchevent to send a message, and that triggers perfectly, but I'd rather be able to press 'enter' instead of clicking send every time to send a message.
Only the send button sends the trigger though, for some reason pressing return in a textedit doesn't seem to be invoking onAction. I've tried using autoindent = false, incase maybe indenting is causing it to not sent onAction or something, but that didn't seem to help.


Second question, can anyone explain how TextList columns work; how to add a column and choose which column to add text to, etc.? I've looked up the syntax on the graalwiki and graalbible and I've seen how they're supposed to be set up but didn't really understand the explanation for that since there wasn't any sort of example of them being used.

Third, I have a scrit that uses loadLines to load files from a text file into an array. LoadLines works perfectly, and I can retrieve the data and use it just fine. When I try to use saveLines on the exact same file, nothing seems to save to the files. It's like it can only read from the file and not write to it.
I've double checked that the NPC server has write rights, this is the exact line from the folder rights for (npcserver):
rw logs/profiles/*.txt
So it should be able to both read from and write to the file. Anyone else having this problem?

Thanks :]
Reply With Quote
  #2  
Old 07-20-2008, 08:31 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
First: I'm not certain that onAction() is called for a GuiMLTextCtrl ... I recommend simply a GuiTextCtrl, there's no reason you need a multi-line one anyway.

Second: Text list columns work like this:
PHP Code:
new GuiScrollCtrl"blah" )
{
  
// stuff here
  
new GuiTextListCtrl"blahblah" )
  {
    
columns = { 050100120 }; // Where (the x value) at where the new column starts
    
addRow0"Hi \t Yo \t ;o \t sup ); // You don't need the spaces, that's just to show.
  }

Third: How are you using saveLines?
PHP Code:
array.saveLines"path/to/file"false ); // The second paramater is to append; false to overwrite, true to append 
__________________
Reply With Quote
  #3  
Old 07-20-2008, 08:53 PM
The_Kez The_Kez is offline
N-Pulse Asst. Manager
The_Kez's Avatar
Join Date: Dec 2007
Posts: 106
The_Kez is on a distinguished road
Send a message via MSN to The_Kez
Quote:
Originally Posted by cbk1994 View Post
First: I'm not certain that onAction() is called for a GuiMLTextCtrl ... I recommend simply a GuiTextCtrl, there's no reason you need a multi-line one anyway.
From the graal wiki:
"onAction() - is invoked when a button control is pressed, you press the enter-key in a text edit control, or move a slider control"
I think it would look a little strange to have an instant messaging window that when you sent a message it just put it as text on the window itself instead of displaying it in a text box. Not sure o:

Quote:
Originally Posted by cbk1994 View Post
Second: Text list columns work like this:
PHP Code:
new GuiScrollCtrl"blah" )
{
  
// stuff here
  
new GuiTextListCtrl"blahblah" )
  {
    
columns = { 050100120 }; // Where (the x value) at where the new column starts
    
addRow0"Hi \t Yo \t ;o \t sup ); // You don't need the spaces, that's just to show.
  }

This is perfect, thanks!

Quote:
Originally Posted by cbk1994 View Post
Third: How are you using saveLines?
PHP Code:
array.saveLines"path/to/file"false ); // The second paramater is to append; false to overwrite, true to append 
PHP Code:
    case "SaveProfile":
    
temp.params[2];
    
temp.params[1];
    echo(
temp.a);
    echo(
temp.b);
    
temp.a.saveLines("profiles/profile_" params[1] @".txt",0);
    break; 
Echo from temp.a:
"Hello","these","are","test","lines"

Echo from temp.b:
"The_Kez"

Like I said, no change is being made to the file at all.
Reply With Quote
  #4  
Old 07-20-2008, 09:24 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Your NPC-Server has rights to logs/profiles/*.txt, but you're trying to write to a file in profiles/*.txt. Your NPC-Server needs read-write rights to profiles/*.txt. Either that, or you need to use temp.a.saveLines("logs/profiles/profile_" @ params[1] @".txt",0);
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #5  
Old 07-20-2008, 09:42 PM
The_Kez The_Kez is offline
N-Pulse Asst. Manager
The_Kez's Avatar
Join Date: Dec 2007
Posts: 106
The_Kez is on a distinguished road
Send a message via MSN to The_Kez
Quote:
Originally Posted by LoneAngelIbesu View Post
Your NPC-Server has rights to logs/profiles/*.txt, but you're trying to write to a file in profiles/*.txt. Your NPC-Server needs read-write rights to profiles/*.txt. Either that, or you need to use temp.a.saveLines("logs/profiles/profile_" @ params[1] @".txt",0);
Oops, yeah I was messing with the command trying to get it to work so I removed logs to check if maybe it only needed the last file in the path, but that didn't work either.

PHP Code:
    case "SaveProfile":
    
temp.params[2];
    
temp.params[1];
    echo(
temp.a);
    echo(
temp.b);
    
temp.a.saveLines("logs/profiles/profile_" temp.@".txt",0);
    break; 
This doesn't work either, it fails to change anything in the file whether I put '/logs' or leave it out.
The exact filepath (checking from the file browser) is:
logs/profiles/profile_The_Kez.txt

So I don't know, I'm baffled by this one.
Reply With Quote
  #6  
Old 07-20-2008, 09:46 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
I'm wondering if logs is only writable via savelog()/savelog2()...

You said that you've tried removing the "logs/" part of the path, but have you tried giving your NPC-Server read-write rights to profiles/*.txt and pointing savelines() to there?
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #7  
Old 07-20-2008, 10:23 PM
The_Kez The_Kez is offline
N-Pulse Asst. Manager
The_Kez's Avatar
Join Date: Dec 2007
Posts: 106
The_Kez is on a distinguished road
Send a message via MSN to The_Kez
Yup, I gave that a try and the files are updating now when you do it directly to profiles as a basefolder so I guess that was the issue.
Thanks for the help
Reply With Quote
  #8  
Old 07-20-2008, 10:40 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by The_Kez View Post
From the graal wiki:
"onAction() - is invoked when a button control is pressed, you press the enter-key in a text edit control, or move a slider control"
I think it would look a little strange to have an instant messaging window that when you sent a message it just put it as text on the window itself instead of displaying it in a text box. Not sure o:
You need to use GuiTextEditCtrl; GuiMLTextEditCtrl is a multiline text box; therefor, when you press enter, it creates a new line. GuiTextEditCtrl is a single-line text box.
__________________
Reply With Quote
  #9  
Old 07-20-2008, 11:04 PM
The_Kez The_Kez is offline
N-Pulse Asst. Manager
The_Kez's Avatar
Join Date: Dec 2007
Posts: 106
The_Kez is on a distinguished road
Send a message via MSN to The_Kez
Bah, I had the controls mixed up. Is there any way I can check if enter has been pressed from a MLTextEdit?
Reply With Quote
  #10  
Old 07-20-2008, 11:04 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
You can use onKeyDown() for a GuiMLTextEdtCtrl. However, you'll have to sacrifice line breaks. I believe the ENTER key is keycode 28.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #11  
Old 07-20-2008, 11:19 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by LoneAngelIbesu View Post
You can use onKeyDown() for a GuiMLTextEdtCtrl. However, you'll have to sacrifice line breaks. I believe the ENTER key is keycode 28.
u can lookup the keycode by doing
PHP Code:
function onKeyPressed(code,key)
{
player.chat code;

__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #12  
Old 07-20-2008, 11:25 PM
The_Kez The_Kez is offline
N-Pulse Asst. Manager
The_Kez's Avatar
Join Date: Dec 2007
Posts: 106
The_Kez is on a distinguished road
Send a message via MSN to The_Kez
Hmm...well like I said this is a dynamic GUI, I looked it up and 28 is indeed enter, but - since it's dynamic and I have to use catchevent how can I check what the keycode is? Because it does...

thiso.catchevent( this.name, "onKeyDown", "onSendMessage" );

So the paramaters for onSendMessage would only be the object, the keycode would be lost wouldn't it?

EDIT:
I've figured this one out for myself so this thread is no longer necessary. Thanks again for the help everyone

Last edited by The_Kez; 07-21-2008 at 01:18 AM.. Reason: Typo
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 12:40 PM.


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