Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   TStaticVar Output Methods (https://forums.graalonline.com/forums/showthread.php?t=134258358)

Imperialistic 03-12-2010 04:59 PM

TStaticVar Output Methods
 
With a little help from DrakilorP2P I created just a script that I'm actually proud of (NOT A SCRIPTER).

Was curious if there was any other easier methods or ways you could handle it?

PHP Code:

function onActionServerSide()
{
  if (
params[0] == "printMyVariable") {
    
myNewVar.loadvars("levels/users/Imperialistic/other/imptest.txt");
    
temp.theVariable base64decode(myNewVar.variable);
    
//echo("Loaded ---> " @ temp.theVariable);
    
findplayer("Imperialistic").sendPM(temp.theVariable);     
  }
  
 if (
params[0] == "saveMyVariable") {
 
myVar = new TStaticVar();
 
myVar.variable params[1];
 
//myVar.secondvariable = "World";
 
myVar.variable base64encode(myVar.variable);
 
myVar.saveVars("levels/users/Imperialistic/other/imptest.txt"1);
 } 
}
 
//#CLIENTSIDE
function onPlayerChats(){
 if (
player.chat ":load"){
      
triggerServer("gui"this.name"printMyVariable");
    }
if (
player.chat.starts("/save")) {
      
temp.argument player.chat.substring(5).trim();
      
temp.arguments temp.argument.tokenize();
      
triggerServer("gui"this.name"saveMyVariable"temp.argument);
  }
 } 


fowlplay4 03-12-2010 06:47 PM

Erm, I know you're excited about your first script but it's just not Code Gallery material.

- It's explicit to your scenario
- Improper Indentation / Random white-spacing
- Only uses events (for this kind of script the purpose is to provide reusable functions)
- There's no comments

Also, player.chat = ":load" should be player.chat == ":load"

TStaticVar + loadvars/savevars Example:

PHP Code:

function onCreated() {
  
// Define Path to File
  
temp.filepath "levels/path/to/randomfile.txt";
  
// Create TStaticVar
  
temp.file = new TStaticVar();
  
// Assign Value to File StaticVar
  
temp.file.testvariable "Hello World!";
  
// Save Values to File
  
temp.file.savevars(temp.filepath0);
  
// Destroy and Re-create File Object (Example Purposes)
  
temp.file "";
  
temp.file = new TStaticVar();
  
// Load File
  
temp.file.loadvars(temp.filepath);
  
// Display Variable
  
echo(temp.file.testvariable);



Imperialistic 03-12-2010 06:55 PM

Last time I checked the Code Gallery was for completed scripts.

But if it's a big deal we can move it (mods hint hint)

Not trying to be a smartass about this...
What's the difference between:
player.chat ==
and
player.chat =

Cloven 03-12-2010 07:00 PM

Quote:

Originally Posted by Imperialistic (Post 1562054)
Not trying to be a smartass about this...
What's the difference between:
player.chat ==
and
player.chat =

" == " is for comparison
" = " is for assigning

fowlplay4 03-12-2010 07:00 PM

Yeah it is for complete scripts but they should have some value to them.

Edit: Cloven's post for = explanation.

Imperialistic 03-12-2010 08:25 PM

I noticed an error that I didn't want to happen..

When I load all of the variables from the .txt file, it only loads the last var entered, any clue why?

=EDIT= Can a mod please move this thread out of the Code Gallery?

cbk1994 03-13-2010 01:44 AM

Quote:

Originally Posted by Imperialistic (Post 1562062)
I noticed an error that I didn't want to happen..

When I load all of the variables from the .txt file, it only loads the last var entered, any clue why?

=EDIT= Can a mod please move this thread out of the Code Gallery?

You're only using one name. If you want multiple slots you'd want something like this

PHP Code:

function onActionServerSide(cmdslotmsg) {
  if (
cmd == "save") {
    
temp.vars.loadVars("data/" player.account ".txt");
    
vars.(@ slot) = msg;
    
vars.saveVars("data/" player.account ".txt"false);
  } else if (
cmd == "load") {
    
temp.vars.loadVars("data/"player.account ".txt");
    
    if (
vars.(@ slot) != null) {
      
player.chat "You don't have a message with the name '" slot "'!";
    } else {
      
player.chat slot ": " vars.(@ slot);
    }
  }
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("/load ")) {
    
temp.load player.chat.substring(6).trim();
    
triggerServer("gui"this.name"load"load);
  } else if (
player.chat.starts("/save ")) {
    
temp.tokens player.chat.tokenize();
    
temp.msg player.chat.substring(tokens[0].length() + tokens[1].length() + 2).trim();
    
    
triggerServer("gui"this.name"save"tokens[1], msg);
  }


Notice how it uses a different variable for each slot.

Imperialistic 03-13-2010 05:07 AM

Thanks Chris, I appreciate it..

Even though it's a huge step from my other script, still trying to figure out all the stuff you did.


All times are GMT +2. The time now is 09:34 AM.

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