Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Using Integer variables (http://www.chiefdelphi.com/forums/showthread.php?t=74343)

programmr 13-02-2009 13:45

Using Integer variables
 
Can anyone show me an example of how to setup an integer variable in the BuiltinDefaultCode example?

Alan Anderson 13-02-2009 13:55

Re: Using Integer variables
 
In general, it's as easy as saying
Code:

int varname;
replacing varname with the name you want to use. The proper place to put that line depends on what you want to use the variable for.

What do you want to use the variable for?

programmr 14-02-2009 13:07

Re: Using Integer variables
 
yes, where to put the variable seems to be our problem. we want to use the variable to keep track of the state of one of our joystick buttons in teleop mode.

int x;
//Now later in the program during teleop routines
if (rightStick->GetRawButton(2)) {
if x = 1 {
x=0; }

else {
x=1; }

x could then be examined to determine the speed of our motors.

Sentient 14-02-2009 17:00

Re: Using Integer variables
 
Where to put x is called scope. If you want x available throughout teleop mode (but you don't need it anywhere else), you can put it directly after OperatorControl(){

You may want to do some more research into scope though. It is an important concept to master.

Rick Wagner 14-02-2009 17:26

Re: Using Integer variables
 
Quote:

Originally Posted by programmr (Post 820609)
yes, where to put the variable seems to be our problem. we want to use the variable to keep track of the state of one of our joystick buttons in teleop mode.

int x;
//Now later in the program during teleop routines
if (rightStick->GetRawButton(2)) {
if x = 1 {
x=0; }

else {
x=1; }

x could then be examined to determine the speed of our motors.

I think you want to be saying

Code:

if (x == 1) { ...
rather than the single equal sign, which is an assignment operator, not a conditional.


All times are GMT -5. The time now is 02:27.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi