Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-12-2010, 04:59 PM
Imperialistic Imperialistic is offline
graal player lord
Imperialistic's Avatar
Join Date: Apr 2007
Location: Florida
Posts: 1,094
Imperialistic is a jewel in the roughImperialistic is a jewel in the rough
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);
  }
 } 
__________________
" It's been swell, but the swelling's gone down. "
Reply With Quote
  #2  
Old 03-12-2010, 06:47 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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);

__________________
Quote:
Reply With Quote
  #3  
Old 03-12-2010, 06:55 PM
Imperialistic Imperialistic is offline
graal player lord
Imperialistic's Avatar
Join Date: Apr 2007
Location: Florida
Posts: 1,094
Imperialistic is a jewel in the roughImperialistic is a jewel in the rough
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 =
__________________
" It's been swell, but the swelling's gone down. "
Reply With Quote
  #4  
Old 03-12-2010, 07:00 PM
Cloven Cloven is offline
Delteria
Cloven's Avatar
Join Date: Dec 2006
Location: Florida, United States
Posts: 542
Cloven has a spectacular aura about
Send a message via AIM to Cloven
Quote:
Originally Posted by Imperialistic View Post
Not trying to be a smartass about this...
What's the difference between:
player.chat ==
and
player.chat =
" == " is for comparison
" = " is for assigning
Reply With Quote
  #5  
Old 03-12-2010, 07:00 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Yeah it is for complete scripts but they should have some value to them.

Edit: Cloven's post for = explanation.
__________________
Quote:
Reply With Quote
  #6  
Old 03-12-2010, 08:25 PM
Imperialistic Imperialistic is offline
graal player lord
Imperialistic's Avatar
Join Date: Apr 2007
Location: Florida
Posts: 1,094
Imperialistic is a jewel in the roughImperialistic is a jewel in the rough
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?
__________________
" It's been swell, but the swelling's gone down. "
Reply With Quote
  #7  
Old 03-13-2010, 01:44 AM
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 Imperialistic View Post
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.
__________________
Reply With Quote
  #8  
Old 03-13-2010, 05:07 AM
Imperialistic Imperialistic is offline
graal player lord
Imperialistic's Avatar
Join Date: Apr 2007
Location: Florida
Posts: 1,094
Imperialistic is a jewel in the roughImperialistic is a jewel in the rough
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.
__________________
" It's been swell, but the swelling's gone down. "
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 04:29 AM.


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