Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-16-2010, 12:22 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
Parse Google Spreadsheets

I wasn't planning on posting this as it's very simple but someone requested it, and it can be very useful .

This simple script will load a Google Docs spreadsheet and turn it into an array of rows/columns.

PHP Code:
public function parseSpreadsheet(url) {
  
temp.req requestURL(url);
  
waitfor(req"onReceiveData"30);
  
  
temp.rows null;
  
temp.lines req.data;
  
  for (
temp.line lines) {
    
temp.row null;
    
    for (
temp.column line.tokenize(char(9))) {
      
row.add(column);
    }
    
    
rows.add(row);
  }
  
  return 
rows;

To get the URL needed, from the Google Spreadsheet choose "Share" then "Publish as web page" at the top-right. Click "Start publishing" and optionally click "Automatically republish as I make changes". Then, from the drop-down list for "Get the link to share", choose "TXT (Plain text)" and copy the link given.



Example usage:
PHP Code:
function onCreated() {
  
temp.url "my_url";
  
temp.rows parseSpreadsheet(url);
  
  for (
temp.row rows) {
   echo(
row);
  }

I'm sure you can think up plenty of uses for this. The one I'm currently using it for on Era is a translation table—the spreadsheet is cached into a script-friendly file which is sent to players on login and can be used for translating text.
Click image for larger version

Name:	Capture 2010-07-15 at 6.20.23 PM.png
Views:	291
Size:	95.7 KB
ID:	51383
__________________
Reply With Quote
  #2  
Old 07-16-2010, 01:22 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Excellent work.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #3  
Old 07-16-2010, 10:37 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Thank you =D

I think this should be added on Login truth be told, great job and thanks for posting (I'd REP but I've repped you already )
__________________
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 12:02 PM.


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