Vizard 7 » Tutorials & Examples » Python Programming » Speaking Vizard's language
7.6

Speaking Vizard's language

This tutorial introduces you to Python, the computer language used to write scripts in Vizard.

 

To do this tutorial, be sure to having Vizard running side-by-side so that you can try every one of the examples as you go along. This is the best way to learn!

 

When you write a script, you are writing a list of directions for Vizard to execute. Vizard will go through your script and do everything you tell it to do. The trick is that you need to give your orders in a language that Vizard understands. That language is Python, a common language in the programming world.  

 

Let's write a short script using Python. Make a new script by selecting File > New Vizard File from the menu:

cows = 4
pigs = 10
beasts = cows + pigs
chickens = "chickens"
roosters = "roosters"
print( cows)
print( pigs)
print( beasts)
print( chickens)
print( roosters)

These statements create new variables and then print those variables. Now run the script and save it. Give it a simple name and save it anywhere convenient. Be sure to avoid using anything other than letters and numbers in your script names.

 

Look at the bottom of your screen and you should see your printout in the input/output window.

A variable can also be an array of other variables. For example, add the following lines to your script and run it again.

barn = [cows, pigs, beasts]
henhouse = [chickens,roosters]
print("The array barn contains:",  barn)
print("The array henhouse contains:", henhouse)

Notice that all three values pop up together in an array surrounded by brackets. In the Python language, each element of an array is identified by its position within that array, starting with position 0. So, for example, our array barn has three elements inside of it. The variable cows is the 0th element, pigs is the 1st element, and beasts is the 2nd element. To refer to an element in the array, type the name of that array and then type the element's position in the array between brackets (for example, barn[0] refers to cows).

 

Add the following lines:

print( cows, "=",  barn[0])
print( roosters, "=",  henhouse[1])

Now run the program again and check out the interactive window.

Interactive Window

So far we've seen how the Interactive Window is used to display Python output. It can also be used to test Python logic. Just type your code in the command line at the bottom of the window and Vizard will process the lines one at a time. So, for example, you can run some of the lines from the beginning of this section:

Speaking Vizard's language

A quick note: Tips on scripts

Looping logic

If-then logic

Functions

An example