|
JackInThe Schnook
Simboarding! ^_^
Join date: 31 Dec 2005
Posts: 46
|
03-28-2006 21:05
This might be simple stuff for some so I appologies. I need to know the best way to share values with other objects.
I see that llemail and a box shouting on a channel can send a string to another object. But how do I take integer data, turn it into a string, send it, and turn it back into an integer for the other object?
What I am trying to do is update a value like a health bar but I need it updated on another objects at the same time. So that both or all objects know eachothers health and can check on it at any time.
Also is this even nessesary? Is there a fast and easy way to share values between scripts other than this method? Either way.. can someone show me or point me to an example somewhere? Thanks
|
|
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
|
03-28-2006 21:43
From: JackInThe Schnook But how do I take integer data, turn it into a string, send it, and turn it back into an integer for the other object? Typecasting
|
|
JackInThe Schnook
Simboarding! ^_^
Join date: 31 Dec 2005
Posts: 46
|
03-29-2006 00:07
Oh thank you! I did a test here and I seem to be stuck on the converting back to a value. I have this something like this so far. First object integer health = 100; llSay(0, (string)health);
And in the second object. listen( integer 0, string name, key id, string health ) { if (health <= 50) { //code here makes this object heal the first object. } } Something like that would work? Also if I had health on the second healer object will it overwrite the health bar I have set inside it? See.. because both have a health bar and both have a value inside them called Health. If something like this code above works then how do I tell who's health is who? haha I hope that makes sense. I'm wondering if that will mess up it's personal health because it is recieving a value that is also called health. Is there a way around that? My plan is to have a few copies of these items in the world and each watching eachothers health bar and then heal eachother when they detect one of them is under 50% And thanks again for the typecasting link! I am trying to understand it and it looks like cool stuff!
|
|
Rifkin Habsburg
Registered User
Join date: 17 Nov 2005
Posts: 113
|
03-29-2006 11:25
From: JackInThe Schnook listen( integer 0, string name, key id, string health ) { if (health <= 50) { //code here makes this object heal the first object. } } Something like that would work? You're almost there. You have to typecast your health into a string to llSay it, and then typecast it back into an integer when you hear it: listen(integer channel, string name, key id, string message) { integer other_health = (integer)message; if (other_health <= 50) { /// code goes here } }From: someone If something like this code above works then how do I tell who's health is who? haha I hope that makes sense. I'm wondering if that will mess up it's personal health because it is recieving a value that is also called health. Is there a way around that? It's best if you give a different name to the other object's health, like I did here. Much less confusing. From: someone My plan is to have a few copies of these items in the world and each watching eachothers health bar and then heal eachother when they detect one of them is under 50% If you've got three or four of these things all in the same area, they'll all be talking to each other and it can get confusing. You will have to add code that will keep track of everyone who is talking. You will want to read up on how to work with lists.
_____________________
Procyon Games: makers of Can't Stop, En Garde, Take it Easy, Danger Zone and Frootcake.
|