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 08-21-2011, 03:54 AM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Storing with serverr.

I was reading through Fowlplay4's scripting guide and I suddenly decided to make a simple script that stores text on the server, safe from updating a level. I read through the forums and found that the use of serverr to store data was a favored method, so I studied some more on the wiki and decided to go and make a simple GUI interface consisting of a MuliLineTextEditCtrl an a Window. All it does is read from the serverr and displays the text in the multiline. Here is what I have.
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
NewsScreen();
  
this.newsteam = {
    
"McChucken""Callimuc"
  
};
  
player.chat "News Updated"//Alerts the player
}

function 
onPlayerChats() {
  if (
player.chat == "!news") {
    
NewsScreen(); //Shows the GUI
  
}
  if (
player.chat.starts("!setnews ")) {
    if (
player.communityname in this.newsteam) { //Protection
      
serverr.news player.chat.substring(9); //Everything after !setnews
    
}
  }
}

function 
NewsScreen() {
  new 
GuiWindowCtrl("News_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "320,240";
    
isexternal true;
    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide true;
    
text "Server News";
    
405;
    
218;
    new 
GuiScrollCtrl("News_MultiLine1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 228;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 308;
      
6;
      
7;
      new 
GuiMLTextCtrl("News_MultiLine1") {
        
profile GuiBlueMLTextProfile;
        
height 16;
        
horizsizing "width";
        
htmlcompatibility true;
        
htmllinks true;
        
text serverr.news;
        
width 283;
      }
    }
  }

The only issue I am having is that when I log out and in again to the server, the text in the multiline is 0 (NULL). What am I missing here. The script has no purpose at all other than helping me learn.

Does the serverr have to be on the serverside to store the data?
__________________
Reply With Quote
  #2  
Old 08-21-2011, 04:39 AM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
It's possible that serverr vars haven't been synced to the clientside yet when that script runs.
Reply With Quote
  #3  
Old 08-21-2011, 04:45 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
A serverr.var is read-only on the clientside. You need to set it on the serverside.

I'm not sure it's a good idea to store something like server news (which is only needed on demand) in a variable that is synced with every client. You also have the problem of strings being chopped to 255 characters if a staff member manually edits the flags from RC.

serverr variables are good when a small amount of data is needed frequently on every client. Such as storing the current state of a weather system.
__________________
Reply With Quote
  #4  
Old 08-21-2011, 05:32 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
As Sales said, you have to set serverr variables on serverside. If they could be set clientside, a "hacker" would be able to change the news for everybody.

The reason it works until you reconnect is that you're temporarily changing the serverr variable on your client only. When you reconnect, the server sends the actual variable. It's like setting a clientr variable on clientside. The value will stick (at least for a while?), but you won't have actually changed the variable on serverside.

Also, RC will trim any server flags down to a certain size (~255 characters?), so if you set server flags with RC, you'll permanently lose anything past that many characters.

You should probably use text files instead of serverr variables for storing server news. There are very few times when server or serverr variables are advisable.
__________________
Reply With Quote
  #5  
Old 08-21-2011, 06:27 AM
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
On Zodiac I use text files, and onLevelFileUpdated() to allow people to edit the news.

When the news text file is updated, I store an updated copy in Control NPC. I.e:

PHP Code:
// Player Logs in
// Send them the News
function onPlayerLogin(pl) {
  
temp.news findnpc("Control-NPC").news;
  
pl.triggerclient("-YourNewsSystem""thegoodword"temp.news);
}

// News is updated
function onLevelFileUpdated(filename) {
  if (
filename == "news/news.txt") {
    
findnpc("Control-NPC").news.loadlines("levels/" filename);
    
updateEveryone();
  }
}

// Send Everyone the News
function updateEveryone() {
  
temp.news findnpc("Control-NPC").news;
  for (
temp.aallplayers) {
    
temp.a.triggerclient("-YourNewsSystem""thegoodword"temp.news);
  }

__________________
Quote:
Reply With Quote
  #6  
Old 08-21-2011, 07:08 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
I always thought onLevelFileUpdated was only for files downloadable in game by the client, having seen that and confirmed that it does indeed work for any file uploaded this is going to make life a lot easier for certain things I wanted to make.

The more you know .
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:23 PM.


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