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