0

I've been trying to implement this but without any success. While I was googling around I saw that this is somehow possible but I can't reach it by myself obviously. This my file tree:

|-Game
|--Assets
|---Animacije
|---Skripte
|----*BlokSistem.js
|---Standard Assets
|----*UI.boo
|---Prefabs
|---Sprites
|---Game.unity

I want to use variable from BlokSistem.js in UI.boo, but without any success. I want to change one and print another. Here is my code for now (UI.boo):

import UnityEngine
import System.Collections

public class UI(MonoBehaviour):

       blokSistem as BlokSistem = GetComponent[of BlokSistem]() #this is line 7 which produces error

       def OnGUI() as void:
           GUI.Box(Rect(0,0,200,50), "Blocks")
           if GUI.Button(Rect(0,60,200,25), "Dirt = "+blokSistem.dirtAmount):
                blokSistem.selectedBlock = blokSistem.dirtBlock
           elif GUI.Button(Rect(0,60,200,25), "Grass = "+blokSistem.grassAmount):
                blokSistem.selectedBlock = blokSistem.grassBlock

I get this error on line 7 (commented it in code above):

The name 'BlokSistem' does not denote a valid type ('not found'). 

This is how I declared my variables in BlokSistem.js:

public var dirtAmount : int;
public var grassAmount : int;
public var selectedBlock : GameObject;

Thanks in advance for help.

1 Answer 1

0

The problem here is compilation order. At the time where your Boo and JS code are compiled, they don't have access to each other. But there is a workaround for that.

Plugin code will be compiled before the "regular" code in your assets. So if your Boo code relies on something in your JS (UnityScript) code, you can put the JS code inside a folder named "Plugins". Keep in mind that this (logically) works only one way around though. So if your JS code ever relies on something in the Boo side, you're out of luck.

This does however (if it is your own code) usually imply it's a good idea to switch to a single language and stick to it. And with focus being more on C# than on UnityScript and particularly Boo, you might want to consider moving over.

Sign up to request clarification or add additional context in comments.

5 Comments

I do know a lot of Python and that is why I want to use boo, it just looks a lot cleaner. This solved the problem but is there any work-around if I want to use something from boo script inside my JS code?
If we're talking "different files", then the same counts as above. But if you're attempting some circular referencing somehow, then you might want to redesign what you're doing. And you're of course free to use whatever language you want, but you might want to note that Boo seems somewhat on its way out: blogs.unity3d.com/2014/09/03/… If it's just you and your personal project, by all means use whatever you like. :)
Pity that they will drop Boo, I just started with Unity3D and was really happy to see python-like language there. Looks like I need to learn C#, despite my avoidance of it for several years already haha :)
Boo will remain supported for now, but in the UI and docs it's on its way out. So yeah, doesn't seem future proof. :)
It should work through the 5 series, since that will remain based on the Mono compiler. The IL2CPP compiler they announced should work with Boo-generated IL but there will probably be differences in details that might not be high priority fixes for Unity

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.