Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Few questions (https://forums.graalonline.com/forums/showthread.php?t=80655)

The_Kez 07-20-2008 07:32 PM

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 :]

cbk1994 07-20-2008 08:31 PM

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 


The_Kez 07-20-2008 08:53 PM

Quote:

Originally Posted by cbk1994 (Post 1405917)
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 (Post 1405917)
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 (Post 1405917)
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.

LoneAngelIbesu 07-20-2008 09:24 PM

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);

The_Kez 07-20-2008 09:42 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1405962)
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.

LoneAngelIbesu 07-20-2008 09:46 PM

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?

The_Kez 07-20-2008 10:23 PM

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 :)

cbk1994 07-20-2008 10:40 PM

Quote:

Originally Posted by The_Kez (Post 1405940)
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.

The_Kez 07-20-2008 11:04 PM

Bah, I had the controls mixed up. Is there any way I can check if enter has been pressed from a MLTextEdit?

LoneAngelIbesu 07-20-2008 11:04 PM

You can use onKeyDown() for a GuiMLTextEdtCtrl. However, you'll have to sacrifice line breaks. I believe the ENTER key is keycode 28.

Deas_Voice 07-20-2008 11:19 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1406009)
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;



The_Kez 07-20-2008 11:25 PM

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 :)


All times are GMT +2. The time now is 08:22 PM.

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