Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   player.loadvars (https://forums.graalonline.com/forums/showthread.php?t=85148)

Schetti 04-14-2009 07:56 PM

player.loadvars
 
Lets say, I wrote in my "notepad":

This is a test.
To show how it fails.

and let this script part work:
PHP Code:

function Notes_list.onSelect(id,text,indx){
  
player.notes.loadvars("Notes/"@player.account@".txt");
  
Notes_title.text player.notes.list[id];
  
this.txt player.notes.(@Notes_title.text);

  
Notes_note.text this.txt;



the text in the GUI looks:
"This is a test.\r\nTo show how it fails.",

someone can tell me how to fix this?

fragman85 04-14-2009 08:14 PM

Try using MLText.

salesman 04-14-2009 08:16 PM

Loadvars is trying to do exactly what it states -- loading variables.
Quote:

Script help for 'loadvars':
TGraalVar.loadvars(str) - loads the variables from a file where each line has the format varname=value
for example, in the textfile you may have:
test=foo
test2=bar

then,

PHP Code:

temp.notes.loadvars("Notes/"@player.account@".txt");
Notes_note.text temp.notes.test

this would display "foo" in the GUI.


for what you're trying to do you might want to check out loadlines().
It will return the lines of the text file as an array, so in your case, it would return the array {"This is a test.", "To show how it fails."}

Schetti 04-15-2009 03:10 PM

isnt there a way, to get the same text, as I wrote down? without any "" or such?

salesman 04-15-2009 06:20 PM

Quote:

Originally Posted by Schetti (Post 1484115)
isnt there a way, to get the same text, as I wrote down? without any "" or such?

I haven't used loadLines() much, but I'm assuming you could just loop through the array of lines and add them to the GUI control one at a time...

Something like this:
PHP Code:

temp.paragraph.loadlines("somefolder/textfile.txt");
for( 
temp.lineparagraph ) {
  
MyGuiControl.text MyGuiControl.text "\n" line;


Anyways, I'm heading to class, so I'm not sure if this makes sense or not

Schetti 04-15-2009 06:38 PM

I dont think this works, and also, because I hardly guess i didnt use correct.

LoneAngelIbesu 04-15-2009 08:36 PM

Quote:

Originally Posted by Schetti (Post 1484155)
I dont think this works, and also, because I hardly guess i didnt use correct.

It should work. You would need to use savelines() to save the file, though.

PHP Code:

function mySaveFunction() {
  
temp.notes MyMLTextGui.text;
  
temp.notes.savelines("myfolder/myfile.txt"1);



napo_p2p 04-15-2009 11:37 PM

Quote:

Originally Posted by fragman85 (Post 1483859)
Try using MLText.

Using a GuiMLTextCtrl should work in this case. Did you try that yet?

Admins 04-16-2009 12:27 AM

Would be interesting to see the content of the notes files, and also what kind of GUI control Notes_Note is.

Schetti 04-16-2009 01:10 PM

1 Attachment(s)
HMM... better posting full script

Sry, I couldnt folow the part with GuiMLTextCtrl, how newb I am. Also tell me if you think thats above my ability level, but I dont think so.
I know there will be lot of nobish stuff, and ignore the boxes, I dont think I will/can use them.
PHP Code:

//#CLIENTSIDE
function onCreated() { 
 }
function 
onPlayerChats()
{  
 if (
player.chat == "/notes")
  {
    
onOpenNotes();
  }
}

function 
onOpenNotes(){
  new 
GuiWindowCtrl("notes_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "508,330";
    
canclose=canminimize=canmaximize=canresize=false;
    
canmove=destroyonhide=true;
    
text = @ player.account @"'s Notes";
    
position = { 665340};

    
//Writing board
    
new GuiScrollCtrl("Notes_note_Scroll") {
      
profile GuiBlueScrollProfile;
      
hscrollbar "alwaysOff";
      
vscrollbar "dynamic";
      
extent = { 329252};
      
position = { 048};

     new 
GuiMLTextEditCtrl("Notes_note") {
        
profile GuiBlueMLTextProfile;
        
horizsizing "width";
        
text "What you want to write down?";
        
position = { 00};
        
extent = { 30016};
      }
    }
    
    
//Title
    
new GuiScrollCtrl("Notes_title_Scroll") {
      
profile GuiBlueScrollProfile;
      
hscrollbar "alwaysOff";
      
vscrollbar "alwaysOff";
      
position = { 83305};
      
extent = { 16118};
      
   new 
GuiMLTextEditCtrl("Notes_title") {
      
profile GuiBlueMLTextProfile;
      
horizsizing "width";
      
text "Title";
      
position = { 50};
      
extent = { 30016};
     }
   }
   
    
//Boxes
    
new GuiCheckBoxCtrl("Notes_boxTodo") {
      
profile GuiBlueCheckBoxProfile;
      
checked true;
      
text "To do";
      
extent = { 10020};
      
position = { 00};
    }
    new 
GuiCheckBoxCtrl("Notes_boxImp") {
      
profile GuiBlueCheckBoxProfile;
      
text "Importand";
      
extent = { 10020};
      
position = { 015};
    }
    new 
GuiCheckBoxCtrl("Notes_boxDone") {
      
profile GuiBlueCheckBoxProfile;
      
text "Done";
      
extent = { 10020};
      
position = { 030};
    }
    
    
//Buttons
    
new GuiButtonCtrl("Notes_bsave") {
      
profile GuiBlueButtonProfile;
      
alpha 0.879999995;
      
text "Apply";
      
position = { 0300};
      
extent = { 8030};
    }
    new 
GuiButtonCtrl("Notes_bclose") {
      
profile GuiBlueButtonProfile;
      
alpha 0.879999995;
      
text "Close";
      
position = { 428300};
      
extent = { 8030};
    }
    new 
GuiButtonCtrl("Notes_bdelete") {
      
profile GuiBlueButtonProfile;
      
alpha 1;
      
text "Delete";
      
position = { 248300};
      
extent = { 8030};

    }
    
    
//List
   
new GuiScrollCtrl("Notes_listscroll") {
      
profile GuiBlueScrollProfile;
      
position = { 3300};
      
extent = { 180300};
      
hScrollBar "dynamic";
      
vScrollBar "dynamic";
      
      new 
GuiTextListCtrl("Notes_list") {
        
profile GuiBlueTextListProfile;
        
0;
        
width 140;
        
fitparentwidth true;

        
clearrows();
        
player.notes.loadvars("Notes/"@player.account@".txt");
        for(
i=0;i<player.notes.list.size();i++)
        {
          
addrow(i,player.notes.list[i]);
        }
      }
    }
  
 }

}
  
  
function 
Notes_bclose.onAction() {
notes_Window1.destroy();
}

function 
Notes_bsave.onAction(){
  if (
Notes_title.text != "")
  {
    
player.notes.loadvars("Notes/"@player.account@".txt");
    if (
Notes_title.text in player.notes.list)
    {
      
player.notes.(@Notes_title.text).add(Notes_note.text);
    }
    else
    {
      
player.notes.list.add(Notes_title.text);
      
player.notes.(@Notes_title.text).add(Notes_note.text);
    }
    
player.notes.savevars("Notes/"@player.account@".txt"false);

    
with("Notes_list"){
      
clearrows();
      
player.notes.loadvars("Notes/"@player.account@".txt");
      for(
i=0;i<player.notes.list.size();i++)
      {
        
addrow(i,player.notes.list[i]);
      }
    }
    
Notes_title.text "";
    
Notes_note.text "";

  }
}

function 
Notes_bdelete.onAction(){
  if (
Notes_title.text != "")
  {
    
player.notes.list.remove(Notes_title.text);
    
player.notes.(@Notes_title.text) = "";
    
player.notes.savevars("Notes/"@player.account@".txt"false);
    
with("Notes_list"){
      
clearrows();
      
player.notes.loadvars("Notes/"@player.account@".txt");
      for(
i=0;i<player.notes.list.size();i++)
      {
        
addrow(i,player.notes.list[i]);
      }
    }
    
Notes_title.text "";
    
Notes_note.text "";
  }
}

function 
Notes_list.onSelect(id,text,indx){ 
  
player.notes.loadvars("Notes/"@player.account@".txt"); 
  
Notes_title.text player.notes.list[id]; 
  
this.txt player.notes.(@Notes_title.text); 

  
Notes_note.text this.txt;



LoneAngelIbesu 04-16-2009 09:20 PM

Quote:

Originally Posted by Schetti (Post 1484354)
<snip>

Why are you still using loadvars()? I'm also not sure why you are using player.notes, anyways. Why not use a temporary variable?


All times are GMT +2. The time now is 09:39 PM.

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