Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Instructions
- // Follow all steps in order beginning from the Google App Script
- // Step 9: Copy/Paste this script into the server object
- // Step 10: Paste the URL of the Google App script into the Google_URL variable
- // Step 11: Proceed to the client script
- string Google_URL = ""; // The URL of the Google App Script
- string spreadsheet_name = "URL_Spreadsheet"; // Write the name of the spreadsheet here the Google App script will create a spreadsheet in your Google Drive with this name.
- key reqURL; // The id of the request for a new URL
- string server_url; // The URL of the server script
- key http_req; // The id of the http request to the Google app script. // May be redundant as the app script creates a new post to the server with its own id.
- default
- {
- state_entry()
- {
- llReleaseURL(server_url); // release all urls assigned to the server_url varaibale
- reqURL = llRequestURL(); // request a new url which will be assigned to the server_url variable
- }
- http_request(key id, string method, string body)
- {
- if(id == reqURL)
- {
- if (method == URL_REQUEST_DENIED)
- {
- llOwnerSay("No free URLs!"); // All URL slots have been used up in the parcel. The number of URLS avaialble in a parcel is the number of allowed prims in the parcel. For example if you have a maximum prim allowance of 100 prims you can only use up 100 URLs. You may never see this message if you dont request URLs in as many scripts as your prim allowance.
- }
- else if (method == URL_REQUEST_GRANTED)
- {
- server_url = body; // assign the url to the server_url variable
- llOwnerSay("Creating spreadsheet.");
- if(Google_URL != "") // if the google appp script url is not blank
- {
- http_req = llHTTPRequest(Google_URL+"?"+"spreadsheet="+llEscapeURL(spreadsheet_name)+"&"+"url="+server_url,[HTTP_METHOD,"POST"],"Create"); // make a request to the Google App Script to create a spreadsheet if one does not exist
- }
- }
- }
- list tmp = llParseString2List(body,["="],[""]); // Parse the body into a command and reference (key/value pair)
- string cmd = llList2String(tmp,0); // command/key
- string ref = llList2String(tmp,1); // reference/value
- if(cmd == "SpreadsheetReady") // If the spreadsheet was newly created
- {
- llOwnerSay("Spreadsheet created.");
- http_req = llHTTPRequest(Google_URL+"?"+"url="+server_url,[HTTP_METHOD,"POST"],"AddURL"); // add the server url to the spreadsheet
- }
- else if(cmd == "url_added") // If the spreadsheet already exists
- {
- llOwnerSay("Server URL added to spreadsheet: " + llUnescapeURL(ref));
- }
- }
- changed(integer change)
- {
- if(change & CHANGED_REGION || change & CHANGED_REGION_START)
- {
- llResetScript(); // URL will release on region change or region restart so reset the script to request a new URL
- }
- }
- }
Add Comment
Please, Sign In to add comment