If your script isn't producing the expected result at runtime, you can debug it in an IDE such as Visual Studio.
[There are lots of ways to debug code. This page suggests one method, using Visual Studio.]
Open the script in Visual Studio.
To open your project in Visual Studio from Game Studio, in the Game Studio toolbar, click (Open in IDE).
Press F9 to add a break point at the required places.
In Visual Studio, press F5 or click Start in the toolbar to run the game in debug mode.
The game starts in a new window. In Visual Studio, on the script page, the first break point highlights and stops the execution.
Verify the state of your variables.
Press F10 (step over) if you want to execute the code line by line, or press F5 to continue code execution.
If Visual Studio doesn't stop at the break point, make sure you attached the script to an entity in the active scene.
For more information about debugging in Visual Studio, see the MSDN documentation.