passing variables between if statements

I get the error messages
"xInt not declaired in this scope"
"yInt not declaired in this scope"
"zInt not declaired in this scope"

if (text.startsWith("x")) {
          String xVal = (text.substring(text.indexOf("x") + 1, text.length()));
          int xInt = xVal.toInt();
		  //colorWipe(strip.Color(xInt, yInt, zInt), 50);
        }

        if (text.startsWith("y")) {
          String yVal = (text.substring(text.indexOf("y") + 1, text.length()));
          int yInt = yVal.toInt();
		  //colorWipe(strip.Color(xInt, yInt, zInt), 50);
        }

        if (text.startsWith("z")) {
          String zVal = (text.substring(text.indexOf("z") + 1, text.length()));
          int zInt = zVal.toInt();
		  //colorWipe(strip.Color(xInt, yInt, zInt), 50);
if (text.startsWith("y")) {
          String yVal = (text.substring(text.indexOf("y") + 1, text.length()));
          int yInt = yVal.toInt();
  //colorWipe(strip.Color(xInt, yInt, zInt), 50);
        }

Here you declare a variable called yInt.
You assign a value to it, and a few tens of nanoseconds later, it goes out of scope.

That strikes me as a little pointless.

It is hard to help when you only supply a snippet of your code. Perhaps you only want a snippet of help?

You did not copy and paste the error messages, so this is only a guess...

Your code should look like:

int xInt=xInitialValue;
int yInt=yInitialValue;
int zint=zInitialValue;

void setup() {
// Something here
}

void loop() {
//
// Something here, including:
//
if (text.startsWith("x")) {
          String xVal = (text.substring(text.indexOf("x") + 1, text.length()));
          xInt = xVal.toInt();
         colorWipe(strip.Color(xInt, yInt, zInt), 50);
        }

        if (text.startsWith("y")) {
          String yVal = (text.substring(text.indexOf("y") + 1, text.length()));
          yInt = yVal.toInt();
	  colorWipe(strip.Color(xInt, yInt, zInt), 50);
        }

        if (text.startsWith("z")) {
          String zVal = (text.substring(text.indexOf("z") + 1, text.length()));
          zInt = zVal.toInt();
	  colorWipe(strip.Color(xInt, yInt, zInt), 50);
//
// More of your loop code here
//
}

This will eliminate the compiler error message. Will it fix things that are wrong? I don't know. You have not shown me all of your code, you have not told me what you intend it to do, you have not told me what it does instead. Neither did you tell me what kind of Arduino you have.

Notice that the declaration of xInt, yInt, and zInt has been moved.

The use of String is a bad thing for most Arduinos due to the limited memory available.

You should read a book about C or C++, concentrating on the meaning of "scope".

Thank you vaj4088. That solved it. :slight_smile:

Divinity82:
Thank you vaj4088. That solved it. :slight_smile:

Without having to learn a thing. How useful was that?

Not that I find any fault with vaj4088, mind you. But, you should have read the links, and learned something.

Hi Divinity82, The very first reply you got also solved the issue, but you would have read about the issue of scope, and understood WHY you do things that way.

Before posting this thread, I did read what is in the link. As well as many others. Maybe you should look closely at the link... It's contents are WRONG and misleading. Here, let me show you...

int gPWMval;  // any function will see this variable

void setup()
{
  // ...
}

void loop()
{
  int i;    // "i" is only "visible" inside of "loop"
  float f;  // "f" is only "visible" inside of "loop"
  // ...

  for (int j = 0; j <100; j++){
  // variable j can only be accessed inside the for-loop brackets
  }

}

What exactly was done with "gPWMval"? Where was it used? Where do I call it?
Oh right... If I knew that, I wouldn't be getting bashed on here for asking a question.
Huh. Go figure.

Divinity82:
Before posting this thread, I did read what is in the link. As well as many others. Maybe you should look closely at the link... It's contents are WRONG and misleading.

Crap. That just shows that you didn't look at that example closely enough.

Here, let me show you...

int gPWMval;  // any function will see this variable

void setup()
{
  // ...
}

void loop()
{
  int i;    // "i" is only "visible" inside of "loop"
  float f;  // "f" is only "visible" inside of "loop"
  // ...

for (int j = 0; j <100; j++){
  // variable j can only be accessed inside the for-loop brackets
  }

}




What exactly was done with "gPWMval"? Where was it used? Where do I call it?

It's very clearly said that gPWMval can be used inside any function. You don't call a variable, but you can use it wherever you want.

Oh right... If I knew that, I wouldn't be getting bashed on here for asking a question.
Huh. Go figure.

Being less of a smart-ass would also help. Go figure.

So why would 2 out of the 3 variables be 0 when any number is assigned to them.
Such as each of the sliders 0-255 max for red green and blue... i moved any one of them to say 5 (for example) boom it outputs 5 when i print it to serial. but then lets say i move blue to 5 (lite turn dim blue) then move red to 5 (turns dim red).. weird... should it be dim purple? So i print xInt, yInt and zInt to serial... 5, 0, 0.

You described the behavior of code that we cannot see.

WiFi16LED.h

REMOVED

ino

REMOVED

Dangit... I guess I really should have read that link more carefully...
Setting the variables as globals fixed it.

Divinity82:
Dangit... I guess I really should have read that link more carefully...

I'm glad you finally got something out of that link. See, it wasn't so bad after all. :smiley:

Setting the variables as globals fixed it.

What, so you removed the code from post #12? You shouldn't do that - you should leave the thread intact for people who read it in the future, not vandalise it because you have what you want.

Well, as it was stated before. The solution is in the link. Why would they need my broken code?

Divinity82:
Well, as it was stated before. The solution is in the link. Why would they need my broken code?

To make sense of the other comments in the thread?

Divinity82:
Well, as it was stated before. The solution is in the link. Why would they need my broken code?

What aarg said. It helps people to put 2 and 2 together. (And hopefully get 4. :slight_smile: )

Divinity82:
WiFi16LED.h

REMOVED

ino

REMOVED

Vandalizing threads leads to suspension of your account, be warned.