The script can be placed in any primitive in-world and cycles questions on touch. It requires a notecard called Questions
to be placed into the same primitive as the script is placed. The notecard should contain one question per line with a blank line at the end.
What is the name of the Masai herder? How many cows does the herder have? What is sleeping sickness?
The script has to be configured in order to set the URL_TO_WEBSITE
constant to the URL of the website where radio.php
is found.
/////////////////////////////////////////////////////////////////////////// // Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // // rights of fair usage, the disclaimer and warranty conditions. // /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // CONFIGURATION // /////////////////////////////////////////////////////////////////////////// // Set this to the website URL string URL_TO_WEBSITE = ""; /////////////////////////////////////////////////////////////////////////// // INTERNALS // /////////////////////////////////////////////////////////////////////////// key nQuery = NULL_KEY; integer nLine = 0; list qList = []; string question = ""; default { state_entry() { integer itra = llGetInventoryNumber(INVENTORY_NOTECARD)-1; do { if(llGetInventoryName(INVENTORY_NOTECARD, itra) == "Questions") jump found_notecard; } while(--itra>0); llOwnerSay("Failed to find notecard."); return; @found_notecard; nQuery = llGetNotecardLine("Questions", nLine); } dataserver(key id, string data) { if(id != nQuery) return; if(data == EOF) state questionnaire; if(data == "") jump next_line; qList += data; @next_line; nQuery = llGetNotecardLine("Questions", ++nLine); } changed(integer change) { if(change & CHANGED_INVENTORY) llResetScript(); } on_rez(integer num) { llResetScript(); } } state questionnaire { state_entry() { llListen(0, "", "", ""); } touch_start(integer num) { question = llList2String(qList, 0); qList = llDeleteSubList(qList, 0, 0); qList += question; llSay(0, question); } listen(integer channel, string name, key id, string message) { nQuery = llHTTPRequest("http://" + URL_TO_WEBSITE + "/radio.php?q=" + llEscapeURL(question) + "&v=" + llEscapeURL(name) + "&a=" + llEscapeURL(message), [], ""); } http_response(key request_id, integer status, list metadata, string body) { if(nQuery != request_id) return; if(body == "OK") return; llSay(DEBUG_CHANNEL, "Could not contact radio website. Please contact support."); } changed(integer change) { if(change & CHANGED_INVENTORY) llResetScript(); } on_rez(integer num) { llResetScript(); } }