Python

I decided to start learning python for integration with Unity. Im sure its no easy task, but im looking for a challenge. Im curious, will Python v3.x work for use with Unity? This may be a very noob-ish question, but i would rather start off on the right foot than find out later that v2 is supported and v3 is not.

Im gonna just DL and dive in, but i would like to here from you regarding your opinions or what-have-you.

Any advice, comments, or whatever is welcome…too much free time!! First forum post… be kind, rewind : p

Unity doesn’t use Python at all. It uses Boo, which has a Python-like syntax.

–Eric

I saw one person integrated the Unity API with Python, which makes me believe that “anything?” can be done with Python. Actually it was IronPython if that makes a difference, which i guess integrates with the .Net libraries and framework. I have a great Asset idea for Unity(might be in the works) and i think using Python is the way to go, am i barking up the wrong branch on the same tree?

Maybe i should start typing boo instead then…?

If you’re looking to start from scratch anyway, I’d suggest you learn C# or Unity’s version of JS (commonly known as Unity Script). While it does support Boo, not many people use it. You’ll have much better luck finding tutorials, examples and just overall assistance with one of the more common languages.

I am already proficient using UnityScript, I know C# pretty ok(not a whole lot of difference imo). Ive been reading up on the Boo language and it just seems to young…and i dont see much advantage to learning it. I think id much rather learn Python over Boo, but integrating with Unity is kinda a big deal for asset development…so maybe Boo is the way to go.

Perhaps I just don’t understand what asset you’re looking to create. Is there a reason you wouldn’t be able to do it in C# or JS?

Boo is only two years younger than C#. And the creator of Boo now works for Unity.

The main advantage is the python inspired syntax, which allows for clean, human readable code, and less code in general. Boo also has quite a few tricks up it’s sleeve for more experienced programmers.

If you come from a python background, Boo is really nice for you.

Otherwise, I’d recommend C#, many(most?) people here use it so there’s a) more documentation/examples b) any assets you create will likely be interfacing with C# and maybe also unityscript, so then they’d have to keep track of all 3 languages if they need to make any customizations c) C# is used by a lot more than just Unity so it’s not time wasted by learning it. :slight_smile:

There might not be a reason, but my guess is i need to access the framework of the system. My asset idea is: Create a serialization of the users code(classes, variables…etc), then be able to get function overload messages and class variable lists(like when writing native classes and functions). I know intellisense has a tool for C# users, but i would like to make this type of tool available to UnityScript users(this might be well out my reach however, maybe unity is on the case??).

I would like to explore this a bit more, ill most likely be sitting on the boo website today exploring it more. I was reading last night about some of the functionality such as Duck Typing, which makes logical sense im guessing that is one of those boo tricks you are referring to. Do you think that boo code runs as fast or faster than C# or UnityScript code inside Unity? I know thats not exactly the best question :stuck_out_tongue: but im just kinda curious if you can optimize well written code by rewriting it to the boo language(possibly unity can compile it quicker since its the native lang?).

I am actively learning C#, its really not too tough and there are only a few major differences from UnityScript that i have seen so far(mainly being syntax) but i know there are other advantages over US the main being, like you said, it is used by more than just unity.

You can do some interesting things with Duck Typing, but I was actually referring to Boo Generators and Macros. And Boo’s “syntactic sugar” allows you to do some neat things as well:

//swap two values
a,b = b,a

//alternative to if not
return unless gameRunning

They all run at the same speed.

I guess one could argue that Boo can help you write better code since it allows for clean, readable code, and forces to you to properly format it. But I wouldn’t expect any noticeable speed increase.

Thanks, that clarifies a bunch actually. I read the Manifesto, boo seems like a really cool language. Im gonna start working in it today and see what i can do. Ive got a good amount of work ahead of me.

Thanks for your posts, im gonna give it my best shot!

Ugh, none of the code displays on their website. That makes it a tough language to learn indeed ;p, Might be a browser issue? I use firefox, but i tried ie as well. Any ideas? Is there a hard copy(pdf or other) posted somewhere else? All the code boxes are blank on every page. I mainly need access to the keywords page here

The code is collapsed… this has been a problem with their website for a few weeks now.

There should be 3 icons in the blue bar at the top of screen. Press the left one and the code should expand.

Oh wow, i would have never thought to click that, since the tool tip says ('Add Comment To Wiki"). Good workaround.

Thanks!

You know, I have been using Boo for 1+ years now with Unity… and I have NEVER known how to show the code.

I learned either by transferring previous Python experience, or by using “View Source”

I thank you. This is extremely nice. I wish they would fix it so I wouldn’t even have to do that though :stuck_out_tongue:

Keeping what TonyD said in mind, always use http://docs.codehaus.org/display/BOO/Boo+Primer (Bookmark) to view all code without having to always click the button. It’s helpful :slight_smile:

Another nice way to view it, is to download it’s PDF :slight_smile: http://docs.codehaus.org/download/attachments/31934/BooPrimer.pdf

Thats awesome, i was hoping there was a pdf reference. Now even if the internet goes down(god i hope that never happens), i can still have a guide. Thanks for those great links!

Ive noticed one thing right off the bat, code doesnt compile the same in Unity as it would with the boo compiler.

  print "Hello, World!"

which to my understanding will compile in the boo compiler, in Unity you need parenthesis around the string.

 print ("Hello, World!")

Im so use to that anyway working in Unity for almost a year now, im guessing there will be other things that wont compile exactly like the ref examples do.

I havent done any real coding just yet, just been reading and working on other stuff. So far i really like how it reads, and i cant wait to start writing macros!!

You can actually use macros to add this print functionality to Unity:

//Save as 'printx.boo', place in asset folder
import Boo.Lang.Compiler
import Boo.Lang.Compiler.Ast

macro printx:
	for item in printx.Arguments:
		yield [|
			UnityEngine.Debug.Log($item)
		|]

Usage:

printx "hello world" //print string
printx "string1", "string2", "string3" //can print several comma seperated strings

Most things in Boo compile correctly.

But some of the error messages the compiler throws out aren’t terribly descriptive, such as “Expecting RPAREN” rather just say “Rear Parenthesis missing”. And whatever editor you use, make sure you indent with either tabs or 4 spaces. Mixing both in the same project will usually cause the compiler to choke.

I don’t get that? Is it simply s̶h̶o̶r̶t̶ long for :

if (!gameRunning) return;

?

As posted before, he said the code is easier to read. This is clear representation.