Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

2 scripts sharing variables?

Altern8 McMillan
Registered User
Join date: 27 Mar 2007
Posts: 36
05-18-2007 11:37
Hi there,
I run into the following problem. I'm reading in lines from a notecard and building a generic menu out of it. If there are too much of them I run out of memory. So I wanted to make another script to source parts of my original script out, like the listen state and so on.

So I wonder if it is anyhow possible to share variables between 2 different script in one prim. If yes, what's about the memory limitation then, as there are only 16384 Bytes allowed. Let me say I've got a very large list, like 16K and want to share it with another script, I'll run into out of memory don't I?

Hope u got what I wanted to ask, thx in advance

greetz

Altern8
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
05-18-2007 12:00
From: Altern8 McMillan
Hi there,
I run into the following problem. I'm reading in lines from a notecard and building a generic menu out of it. If there are too much of them I run out of memory. So I wanted to make another script to source parts of my original script out, like the listen state and so on.

So I wonder if it is anyhow possible to share variables between 2 different script in one prim. If yes, what's about the memory limitation then, as there are only 16384 Bytes allowed. Let me say I've got a very large list, like 16K and want to share it with another script, I'll run into out of memory don't I?

Hope u got what I wanted to ask, thx in advance

greetz

Altern8


I'd be inclined to revisit exactly what you are trying to do and sub divide the menu's across multiple scripts, i.e. each menu in different notecards controlled by a different script. You can still use a single reader and have it send the data to the different menu handlers although the advantage in terms of number of scripts versus time to read the notecard(s) is not as great as you may think.
_____________________
I'm back......
Ralph Doctorow
Registered User
Join date: 16 Oct 2005
Posts: 560
05-18-2007 12:10
The immediate answer is no you can't share variables between scripts period.

However, you can use link messages between scripts or do hacks like changing the prim description.

I also agree with Newgate though, you might reconsider what you are doing. For example are you making copies of text, creating lists (very inefficient), keeping stuff in memory you aren't actually using etc.

Programming LSL is like programming a single chip computer 20 years ago.
Destiny Niles
Registered User
Join date: 23 Aug 2006
Posts: 949
05-18-2007 12:17
From: Altern8 McMillan
...
So I wonder if it is anyhow possible to share variables between 2 different script in one prim.
...

Use the llMessageLinked(integer linknum, integer num, string str, key id) function and the link_message(integer sender_num, integer num, string str, key id) event to pass the variable values between the scripts.

http://wiki.secondlife.com/wiki/Link_message
Altern8 McMillan
Registered User
Join date: 27 Mar 2007
Posts: 36
05-18-2007 13:27
oh wow, that was fast, indeed.

ok, let me explain a bit more what I am trying to do. I want to build my own parcel music chooser. I know this was done before, but anyway. The idea about it was to configure the genre, the station and the url by using a notecard.

Some example entries:

Electronic, Moscow Deep Radio,http://someurl
Country, Country 1, http://someurl
Alternative,Station X, http://someurl
Electronic,ABF,http://someurl

It's first the genre, then the station name and the url. I wanted to be able to add new stations just by modifying the notecard. The menu should divide into genre -> stations.

From: Ralph Doctorow
...
I also agree with Newgate though, you might reconsider what you are doing. For example are you making copies of text, creating lists (very inefficient), keeping stuff in memory you aren't actually using etc.
...


Yes, you are right, it seems I'm keeping stuff in my memory I'm actually not using. But how else should I do it. Even if I hardcode the stations into the script I will creating a list that I'm actually not using. Do I miss something here?

From: Newgate Ludd
I'd be inclined to revisit exactly what you are trying to do and sub divide the menu's across multiple scripts, i.e. each menu in different notecards controlled by a different script.
...


The idea with the different notecards is great, the problem is still that I want to be able to set as many genres as I want (ok, that's too much), but I don't want be restricted to let me say 5, because I have only 5 scripted readers installed.


From: Destiny Niles
Use the llMessageLinked(integer linknum, integer num, string str, key id) function...


Thx I was not aware that this is posible between scripts as well, thought it was only possible to send messages between linked objects.

so if one of you or anyone else can help me on my thinking blockade I would be very thankful

greetz

Altern8
Ralph Doctorow
Registered User
Join date: 16 Oct 2005
Posts: 560
05-18-2007 13:29
How about a multi-level dialog system, name the notecards by genre, then first show just a list of genres, then when the user picks one, read just that notecard and show only what's on it.
Altern8 McMillan
Registered User
Join date: 27 Mar 2007
Posts: 36
05-18-2007 13:49
From: Ralph Doctorow
How about a multi-level dialog system, name the notecards by genre, then first show just a list of genres, then when the user picks one, read just that notecard and show only what's on it.

Yep, this is exactly what I wanted to do. And I think I will try this out. My thinking was too complicated I guess. I wanted to do it in only one Notecard. But the idea with several is cool also. Thx very much. Now the only problem will be. If I have to read in the notecard everytime I build a submenu it will take ages. Imagine if there are like 50 stations on a list. That's why I wanted to do it on rez, what I found out makes no sense, due to memory limitations. Seems LSL is a bit tricky.

thx again

greetz

Altern8
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
05-19-2007 02:06
From: Altern8 McMillan
Yep, this is exactly what I wanted to do. And I think I will try this out. My thinking was too complicated I guess. I wanted to do it in only one Notecard. But the idea with several is cool also. Thx very much. Now the only problem will be. If I have to read in the notecard everytime I build a submenu it will take ages. Imagine if there are like 50 stations on a list. That's why I wanted to do it on rez, what I found out makes no sense, due to memory limitations. Seems LSL is a bit tricky.

thx again

greetz

Altern8

Personally I myself prefer the multiple notecard solution. Name each notecard after a genre then getting your first genre list is a case of just reading the notecard names, no dataserver events required.

But you can do it in one notecard, all it takes is a little bit of organisation. Use keywords to define the start (and end) of each genre list i.e.

CODE

GENRESTART=Jazz
My Jazz Channel =URL
.....
MY Jazz Channel=URL
GENRESTART=POP
Pop 1=URL
Pop 2 = URL
....


Then when reading the notecard for the first time only store the genre name's and the start and end line numbers for each one. Once selected you can then reread the specific lines to build the station table. I agree it can take a long time if you have lots of stations but teh trick would then be to sub sub menu, keep each menu to 10 items to allow quick access to the main menu again.

Another approach which has been used, but takes a little bit of manual memory handling, is a single string to store the data and build only sections of the lists as required.
_____________________
I'm back......
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
05-21-2007 08:14
One way to break things down would be to have a different script handle each genre. The code in them would be pretty much identical, expect which notecard they are reading their information in from. You would then have a controller script which would trigger states in the other scripts based upon the menu.

Example:
1. User clicks object, control script responds with a list of genres (read off the names of the notecards perhaps).
2. User selects a genre, and the control script triggers and On state for that genres script.
3. When the genres on state triggers, it reads in the data (or already had it stored) and displays a new menu to the user.
4. User selects an option off the sub-menu and the genre script receives the menu input and sends out a llLinkMessage to another script which in turn changes the music to the stream it receives.
5. After sending the message, the genre script resets itself to the default state.

So, you'll have three different types of script but multiple copies of one of them.