Changing variables in NXC
-
- Posts: 12
- Joined: 16 Nov 2010, 01:29
Changing variables in NXC
I am new to NXC so how do I change a variable? I made the variable that turn = 0 and it is all set up. But how do I change it to another number?
I take the place of Penguinplus from the old forums.
Re: Changing variables in NXC
Not quite sure what you mean here.
If you want to change the variable name throughout the program then use search and replace.
If you want to change the value of turn then any assignment will do -
turn = put in the name of any other variable here
turn = put in any number here
turn = turn + 16*2
put in the name of any other variable here = turn
put in the name of any other variable here = turn + 56
Is that the sort of thing you mean?
If you want to change the variable name throughout the program then use search and replace.
If you want to change the value of turn then any assignment will do -
turn = put in the name of any other variable here
turn = put in any number here
turn = turn + 16*2
put in the name of any other variable here = turn
put in the name of any other variable here = turn + 56
Is that the sort of thing you mean?
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
-
- Posts: 12
- Joined: 16 Nov 2010, 01:29
Re: Changing variables in NXC
I try to change a variable in a if statement bot it gives me errors.
I take the place of Penguinplus from the old forums.
-
- Posts: 252
- Joined: 22 Oct 2010, 20:05
- Location: The United States of America
- Contact:
Re: Changing variables in NXC
It often helps to provide your code for us to read. Even more so, it is easier to read if you provide your code this way:
[/code]
Maybe you accidentally did the wrong combination of wether or not to use spaces for certain commands. It's a possible exlpanation for why your if statement isn't working, but like I said, it's best if you provide your code for us to see.
Code: Select all
[code](your code)
Maybe you accidentally did the wrong combination of wether or not to use spaces for certain commands. It's a possible exlpanation for why your if statement isn't working, but like I said, it's best if you provide your code for us to see.
-Hayden
Re: Changing variables in NXC
I think you should try reading the NXC Tutorial and the NXC Programmer's Guide. Both of these have many examples of how you use variables.penguinplus wrote:I am new to NXC so how do I change a variable? I made the variable that turn = 0 and it is all set up. But how do I change it to another number?
Code: Select all
task main()
{
int turn = 0;
turn++; // increment turn
turn = 4; // set turn's value to 4
turn += 4; // add 4 to turns current value
turn = Random(); // set turn to a random number
}
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Who is online
Users browsing this forum: No registered users and 0 guests