Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Simple Question Time - Printing a String to the screen?

Piggie Paule
Registered User
Join date: 22 Jul 2008
Posts: 675
08-26-2009 10:08
string test;
integer col = 1;

if(col == 1) {string test = "Hello";}

llOwnerSay( test );


Does not error on compilation, but obviously something wrong here, and can't find out the simple answer to this.

Looked here:

http://wiki.secondlife.com/wiki/LlOwnerSay
and
http://wiki.secondlife.com/wiki/String

But does not really help me.

I know it's a simple basic thing, but kinda stuck with the syntax needed here.
Cheree Bury
ChereeMotion Owner
Join date: 6 Jun 2007
Posts: 666
08-26-2009 10:22
From: Piggie Paule
string test;
integer col = 1;

if(col == 1) {string test = "Hello";}

llOwnerSay( test );


Does not error on compilation, but obviously something wrong here, and can't find out the simple answer to this.

Looked here:

http://wiki.secondlife.com/wiki/LlOwnerSay
and
http://wiki.secondlife.com/wiki/String

But does not really help me.

I know it's a simple basic thing, but kinda stuck with the syntax needed here.



You have declared the 'string test' twice.

Try this:

string test;
integer col = 1;

if(col == 1) {test = "Hello";}

llOwnerSay( test );
_____________________
Visit ChereeMotion - Life's Best Pinup Poses
http://slurl.com/secondlife/Wild%20Rice/38/230/51
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
08-26-2009 10:32
You've defined "test" twice .... once in your first line and again in the if statement. I'm surprised the compiler didn't spit up. As for why it didn't say anything, my guess is that there's something in the parts of the script that you didn't show here that either bypasses the if test or reloads "test" with the value " ".
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
08-26-2009 10:40
It's also possible that something in parts of the script that you didn't show us is either bypassing the if test or is reloading the variable "test" with the value " ".
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Piggie Paule
Registered User
Join date: 22 Jul 2008
Posts: 675
08-26-2009 10:59
From: Cheree Bury
You have declared the 'string test' twice.

Try this:

string test;
integer col = 1;

if(col == 1) {test = "Hello";}

llOwnerSay( test );



Thanks, that was exactly the problem

I didn't realise that once you have declared (in this instance) "test" as the string, that you could just use it's name on it's own.

Again, (give me a slap) in Basic, I'm used to having to refer to it as a string each time as in.

A$="hello"

So each time you used the string you have to use the $ symbol.

I suppose (now I know) as you have at the start identified it as a string, from then on the scrip knows it's a string.

Logical, but just not what I was used to :)
Piggie Paule
Registered User
Join date: 22 Jul 2008
Posts: 675
08-26-2009 11:00
From: Rolig Loon
It's also possible that something in parts of the script that you didn't show us is either bypassing the if test or is reloading the variable "test" with the value " ".


Thanks for the suggestion, it was just as I was declaring the string more than once which was screwing it.

Another tiny hurdle overcome :)
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
08-26-2009 11:27
From: Piggie Paule
I suppose (now I know) as you have at the start identified it as a string, from then on the scrip knows it's a string.

Not quite true. It not a matter of defining it "at the start." It has to be defined within the scope where you are using it. Compare .....

CODE

string test;
default{
state_entry{
test = "Hello!";
}
touch_start(integer num){
llSay(0, test);
}
}


with .....

CODE

default{
state_entry{
string test = "Hello!";
}
touch_start (integer num){
string test;
llSay(0, test);
}
}


In the first case, "test" is defined globally -- its scope is the entire script, so you can give it a value in one event and use it in another. In the second case, "test" is defined separately in each event. It's actually a different variable. Loading it with "Hello!" in state_entry has no effect when you try to llSay it in touch_start. In THAT scope, "test" has its default value, " ".

ETA: You may want to spend a little time reviewing these and other core topics in one or more of the tuorials at . Some are better than others, but they may help point you in the right direction as you come up against questions like this. :)
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at