Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

changing string data to integer

Fred Wachtel
Registered User
Join date: 11 May 2008
Posts: 6
10-04-2008 08:04
I am using the basic -high altitude rezzer- on the SL wiki. I wanted to add a feature to ask the user for the altitude to go to and rather than use a menu, just accept the numeric from the chat window. I am a beginning scripter, so I am having trouble with the syntax. code follows:

//High Altitude Rezzer
//Creator: Jesse Barnett
integer target_height = 435;//Set the elevation you want to go to here. Maximum you can rez objects is 4096.
float zSpeed = 500.0;
vector x;
vector w;
list grnd;
vector ground;
vector rez_obj_offset = <0.0, 0.0, -0.5>;
//
integer channel = 0;
//Adjust this as necessary for postion of
//rezzed object in relation to vehicle. (no more then 10.0 in any axis)
default{
on_rez(integer start_param) {
llResetScript();
}
state_entry(){
grnd = [];
grnd += llGetPos(); // back to ground position?
ground = llList2Vector(grnd, 0);
vector pos = llGetPos(); // current position?
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
if(pos.z >= (target_height - 5)){
state descend;
}
llSetText("Sit and touch to ascend", <0,0,0>,1.0);
//
integer listen_handle = llListen(0, "", llGetOwner(), "";);
}
listen( integer channel, string name, key id, string msg )

target_height = (integer) msg

{
llSetText("Sit and touch to ascend", <0,0,0>,1.0);
}
touch_start(integer total_number){
llSetStatus(STATUS_PHYSICS, TRUE);
x = llGetPos();
x.z = target_height;
llTarget(x,50);
}
not_at_target(){
llApplyImpulse(llGetMass()*<0,0,zSpeed>,FALSE);
}
at_target(integer ascend, vector target, vector cPos){
llTargetRemove(ascend);
llMoveToTarget(target,1);
llSetTimerEvent(5.0);
}
timer(){
vector pos = llGetPos();
if(pos.z >= (target_height - 1)){
llStopMoveToTarget();
llApplyImpulse(-llGetMass()*llGetVel(),FALSE);
llSetStatus(STATUS_PHYSICS, FALSE);
llRezObject(llGetInventoryName(INVENTORY_OBJECT, 0), llGetPos() + rez_obj_offset, ZERO_VECTOR, ZERO_ROTATION, 42);
state descend;
}
}
}
state descend{
state_entry() {
vector pos = llGetPos();
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
if(pos.z <= (ground.z + 5)){
state default;
}
llSetText("Sit and touch to descend", <0,0,0>,1.0);
}
touch_start(integer total_number){
llSetStatus(STATUS_PHYSICS, TRUE);
w = llGetPos();
w.z = ground.z;
llTarget(w,50);
}
not_at_target(){
llApplyImpulse(llGetMass()*<0,0,-500>,FALSE);
}
at_target(integer descend, vector target2, vector Pos){
llTargetRemove(descend);
llMoveToTarget(target2,1);
llSetTimerEvent(5.0);
}
timer(){
vector pos = llGetPos();
if(pos.z <= (ground.z + 1)){
llStopMoveToTarget();
llApplyImpulse(-llGetMass()*llGetVel(),FALSE);
llSetStatus(STATUS_PHYSICS, FALSE);
llSetPos(ground);
state default;
}
}
}
Kain Cleaver
Registered User
Join date: 24 Jan 2006
Posts: 178
10-04-2008 09:00
whatever you name your string command just add (integer) in front of it..

so heres a small sample

so in your listen area youd put something liek this

happy = (integer)string;
Kain Cleaver
Registered User
Join date: 24 Jan 2006
Posts: 178
10-04-2008 09:02
you forgot to put a ; at the end of your line

target_height = (integer) msg

a good indication of whats wrong is whenever you get a error it will leave the cursor next to whatever it is that may be wrong
Fred Wachtel
Registered User
Join date: 11 May 2008
Posts: 6
Try, try again
10-04-2008 09:37
Thanks so much for offering your assistance. I'll give your suggestions a try.
Fred Wachtel
Registered User
Join date: 11 May 2008
Posts: 6
10-04-2008 10:01
Seems I still get a syntax error on the line:

target_height = (integer) msg;
Fred Wachtel
Registered User
Join date: 11 May 2008
Posts: 6
10-04-2008 10:08
Spoke too soon, found I had a curly bracket below that line that should have been above. Complies ok, but I've broke the script from running correctly. It doesn't have the touch option in the pie menu. I'll keep looking
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-04-2008 11:39
From: Fred Wachtel
Spoke too soon, found I had a curly bracket below that line that should have been above. Complies ok, but I've broke the script from running correctly. It doesn't have the touch option in the pie menu. I'll keep looking

Nice to see this old script of mine still get used and absolutely wonderful to see new people scripting.
Kain caught the first mistake and you Fred caught the second, which is a great start. You must have introduced a formatting error in while making the changes. You should have come up with this:
CODE
//High Altitude Rezzer
//Creator: Jesse Barnett
integer target_height = 100;//Set the elevation you want to go to here. Maximum you can rez objects is 4096.
float zSpeed = 500.0;
vector x;
vector w;
list grnd;
vector ground;
vector rez_obj_offset = <0.0, 0.0, -0.5>;
//Adjust this as necessary for postion of
//rezzed object in relation to vehicle. (no more then 10.0 in any axis)
integer chan = 273;
default{
on_rez(integer start_param) {
llResetScript();
}
state_entry(){
grnd = [];
grnd += llGetPos(); // back to ground position?
ground = llList2Vector(grnd, 0);
vector pos = llGetPos(); // current position?
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
if(pos.z >= (target_height - 5)){
state descend;
}
llSetText("Sit and touch to ascend", <0,0,0>,1.0);
llListen(chan, "", llGetOwner(), "");
}
listen( integer channel, string name, key id, string msg ){
target_height = (integer) msg;
llSetText("Sit and touch to ascend", <0,0,0>,1.0);
}
touch_start(integer total_number){
llSetStatus(STATUS_PHYSICS, TRUE);
x = llGetPos();
x.z = target_height;
llTarget(x,50);
}
not_at_target(){
llApplyImpulse(llGetMass()*<0,0,zSpeed>,FALSE);
}
at_target(integer ascend, vector target, vector cPos){
llTargetRemove(ascend);
llMoveToTarget(target,1);
llSetTimerEvent(5.0);
}
timer(){
vector pos = llGetPos();
if(pos.z >= (target_height - 1)){
llStopMoveToTarget();
llApplyImpulse(-llGetMass()*llGetVel(),FALSE);
llSetStatus(STATUS_PHYSICS, FALSE);
llRezObject(llGetInventoryName(INVENTORY_OBJECT, 0), llGetPos() + rez_obj_offset, ZERO_VECTOR, ZERO_ROTATION, 42);
state descend;
}
}
}
state descend{
state_entry() {
vector pos = llGetPos();
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
if(pos.z <= (ground.z + 5)){
state default;
}
llSetText("Sit and touch to descend", <0,0,0>,1.0);
}
touch_start(integer total_number){
llSetStatus(STATUS_PHYSICS, TRUE);
w = llGetPos();
w.z = ground.z;
llTarget(w,50);
}
not_at_target(){
llApplyImpulse(llGetMass()*<0,0,-500>,FALSE);
}
at_target(integer descend, vector target2, vector Pos){
llTargetRemove(descend);
llMoveToTarget(target2,1);
llSetTimerEvent(5.0);
}
timer(){
vector pos = llGetPos();
if(pos.z <= (ground.z + 1)){
llStopMoveToTarget();
llApplyImpulse(-llGetMass()*llGetVel(),FALSE);
llSetStatus(STATUS_PHYSICS, FALSE);
llSetPos(ground);
state default;
}
}
}

You will see that I made three other changes. First was renaming channnel to chan because channel is defined in the listen event. The second is extremely important, never, ever leave an always open listen on channel 0. The simulator is having to process every single chat message made in the sim 24 hours a day when you do this. Plus you are constantly redefining the target as everything you personally say, even if you are talking to someone. Use a different, non common channel. The last thing I did was remove the listen handle, a listen handle is only defined if you are going to be removing the listen.

Finally, I always recommend new people give LSLEditor a try. It helps make learning to script much easier and points out any problems you have introduced into the script.

http://www.lsleditor.org/
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Fred Wachtel
Registered User
Join date: 11 May 2008
Posts: 6
10-04-2008 14:51
Jesse Barnett, you are so gracious to share your ideas with the world, then put up with someone like me butchering it. lol

Thank you so much for your input and knowledge. Also, I'll try the editor. I was trying to bring up my own open sim at home to work with so i would have a little more control over the sandbox.. I have only programmed in Basic and access, neither of which prepared me for this learning experience. but I'm trying.

In case you are curious, I was building this to front end a holodeck.

Thanks again for your help and hope to hear from you again in the future.
bobbyb30 Swashbuckler
Registered User
Join date: 8 Sep 2008
Posts: 46
10-04-2008 18:10
From: Fred Wachtel
Jesse Barnett, you are so gracious to share your ideas with the world, then put up with someone like me butchering it. lol

Thank you so much for your input and knowledge. Also, I'll try the editor. I was trying to bring up my own open sim at home to work with so i would have a little more control over the sandbox.. I have only programmed in Basic and access, neither of which prepared me for this learning experience. but I'm trying.

In case you are curious, I was building this to front end a holodeck.

Thanks again for your help and hope to hear from you again in the future.



LSL Editor is a great tool if you plan on scripting a lot.
_____________________
Large supporter and contributer of LSL Editor available at lsleditor.org
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
10-04-2008 20:04
From: Fred Wachtel
Jesse Barnett, you are so gracious to share your ideas with the world, then put up with someone like me butchering it. lol

Nope, you have the wrong idea. I think I can speak for everyone that has contributed to the forums over the years in saying that YOU are our target audience. This last couple of years has been simply the most awesome experience of my life. I knew absolutely nothing about coding/scripting when I started here and asked so many dumb questions at first. Finally I had a chance to pay it forward and start answering questions from other new scripters. There is absolutely no way to describe the feeling of watching people come here with their tentative, basic, first question and watch the questions become more complex until they too post their first script to the library.

I can think of no other place that is as special as these Content Creation Forums. As us "oldies" retire and post answers more infrequently, others step in to take up the reins. It is still thrilling to see an old, familiar name pop in here every now and then but it is nothing compared to seeing new names become familiar over time.

Hoping to see much more of you here.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum