Okay so letโ€™s put a variables block into practice. So what weโ€™re going to do is take these ones and zeroes that refer to the CAN channel and create variables for them. So we can call them CAN channel 1 and CAN channel 2 without confusing the array number with them. So Iโ€™m going to start by creating a constant integer (const int ch1) and call it channel 1. So what this is saying is that weโ€™re going to set this integer on startup and thatโ€™s it, we canโ€™t change it anymore. It stays throughout runtime to this value that we set it at. The reason why weโ€™re doing that is weโ€™re going to put that in here on the, on CanMessage hook. On CanMessage hook requires a constant in for channel, so you canโ€™t go changing it during runtime and confusing those hooks. So we do the same thing with channel 2. What weโ€™ll go and weโ€™ll do now is weโ€™ll go through and change all the values to our new integers.

Now you can see that we replaced all these values with our variables, so what we can do is if, letโ€™s say weโ€™re going to use a five channel device, maybe we want to use channel 2 and 3 instead so what we can do is we can come up here and change the variables, recompile and it allows us to reuse the same code a lot easier than going through and finding and replacing all the values. So thatโ€™s how we can utilize the variables and our t scripts to make things a little bit easier to read and reusable

Back to: Intro to t Programming > Intro to t Programming: Part 3