llSetTexture Question
|
|
Minoru Musashi
Oriental Flair
Join date: 20 Oct 2004
Posts: 76
|
06-24-2007 06:46
I created a script to announce in chat the artist name and song currently playing from my radio station. This has served its purposes well. Since it doesn't look like we will be able to load images from an external source anytime soon I thought I would try to load them from within Second Life. I'm not having much luck getting this accomplished. The script I'm using below: key now_playing; string text; default { state_entry() { llSetTimerEvent(60.0); } timer() { { now_playing = llHTTPRequest("website url",[HTTP_METHOD,"GET"],""  ; } } http_response(key request_id, integer status, list metadata, string body) { text=llGetSubString(body, 0, llStringLength(body) - 0); llSetText(text,<1,1,1>,1.0); llSay(0,text); llSetTexture(text,ALL_SIDES); } } The llSetText and llSay work perfectly; however the llSetTexture returns an error that the texture cannot be found. All of the textures are in the object that the script is running from. I tried llSetPrimitiveParams too, but that just displays a gray texture. Any ideas. Another task I wish the script would do would be to check if the result is the same as last result. Right now the script will announce the song every 60 seconds. I would love it if it would be able to not repeat that announcement. For example the song playing is now "song title" check in 60 seconds if "song title" is the same go back to beginning. Thanks
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
06-24-2007 07:07
I suspect that "text" *looks* good, but either has leading or trailing space characters (might try the nifty new llStringTrim() function), or perhaps there's hidden "special characters" in there, which might necessitate a lookup table to delete them or swap them with something valid in an inventory name. In either case, if llGetInventoryType(text) != INVENTORY_TEXTURE, it's not gonna work. From: Minoru Musashi Another task I wish the script would do would be to check if the result is the same as last result. Right now the script will announce the song every 60 seconds. I would love it if it would be able to not repeat that announcement. It's certainly possible to have a global variable "previous_text" that you check in the http_response() handler, and if it's == text, return, till the next timer event. [Edit: Better, old_body ?= body, before extra computation to torture body into text.] A more complicated approach would be to have the web server delay response till a new song was playing... probably timeout conditions to be handled, etc.
|
|
Minoru Musashi
Oriental Flair
Join date: 20 Oct 2004
Posts: 76
|
06-24-2007 12:52
From: Qie Niangao I suspect that "text" *looks* good, but either has leading or trailing space characters (might try the nifty new llStringTrim() function)... llStringTrim fixed the problem. I changed this: text=llGetSubString(body, 0, llStringLength(body) - 0); llSetText(text,<1,1,1>,1.0); llSay(0,text); llSetTexture(text,ALL_SIDES); to this: text=llGetSubString(body, 0, llStringLength(body) - 0); string src = text; text = llStringTrim(src, STRING_TRIM); llSetText(text,<1,1,1>,1.0); llSay(0,text); llSetTexture(text,ALL_SIDES); and it fixed the problem Thank you for your help!
|
|
Minoru Musashi
Oriental Flair
Join date: 20 Oct 2004
Posts: 76
|
08-12-2007 10:43
Can anyone help me with adding some error handling to this script? -------------------------------------------------------------------------------- key now_playing; string text; default { state_entry() { llSetTimerEvent(60.0); } timer() { { now_playing = llHTTPRequest("http://tokyohits.com/radio/artist-album.html",[HTTP_METHOD,"GET"],""  ; } } http_response(key request_id, integer status, list metadata, string body) { text=llGetSubString(body, 0, llStringLength(body) - 0); string src = text; text = llStringTrim(src, STRING_TRIM); llSetText(text,<1,1,1>,1.0); llSetTexture(text,ALL_SIDES); } } ------------------------------------------------------------------- The script will generate an error if the texture is not available. Is there a way to tell the script if the texture is not available load an alternate texture instead? Thanks
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
08-12-2007 12:13
Kinda. You could call llGetInventoryType on the prospective texture name string, and if it returns INVENTORY_TEXTURE, you're good-to-go; otherwise have to punt with some default texture. (If you ever switch to using texture keys not in the object's inventory, though, I think there's pretty much no way to know if it's a real texture or not.)
|
|
Lyn Mimistrobell
(waiting)
Join date: 11 Jan 2007
Posts: 179
|
08-13-2007 09:59
Can I ask what the purpose is of this bit:
text = llGetSubString(body, 0, llStringLength(body) - 0);
Maybe it's usefull, but I don't see the point...
Lyn
|
|
Minoru Musashi
Oriental Flair
Join date: 20 Oct 2004
Posts: 76
|
08-13-2007 11:13
From: Lyn Mimistrobell Can I ask what the purpose is of this bit:
text = llGetSubString(body, 0, llStringLength(body) - 0);
Maybe it's usefull, but I don't see the point...
Lyn Well I'll start off by saying I'm not a scripter. I basically take bits and pieces from the wiki and suggestions of people and try to get it to do what I want. My radio station updates the URL (artist-album.html) with the current artist and album that is playing. I use that "string" (if that's what it's called) to get that information into Second Life. This particular script updates a box and displays the album cover of the song that is currently playing. The texture of the album cover is in the box. It's not perfect and doesn't work well with those albums that contain "various artists" which is why I'm looking for some sorta of error control. Plus I don't like seeing the script error. I want it to load a standard (logo) image if the texture cannot be found. I played around with the llGetInventoryType but couldn't get it to compile right let alone work. It's my understanding that you cannot load a texture from a web location. Ideally that would work better. Save me some $L too! I have another HTTPRequest script that will announce the artist and song name in chat so when people visit my shops they can hear (see in chat) what's currently playing. Feel free to check out one of my shops to see it in action. The locations are in my picks. I customized a URL for my profile page too! I'm open to any suggestions or help in optimizing what I have done or would like to do. I'm using the SAM Broadcaster to generate these web pages. At first I used a Shoutcast Statistics script where I needed to strip out characters before and after the part I wanted. That is no longer needed. Maybe that is what you are referring to.
|