Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Converting external Python script to BooScript

Discussion in 'Scripting' started by ElnuDev, Apr 3, 2018.

  1. ElnuDev

    ElnuDev

    Joined:
    Sep 24, 2017
    Posts:
    298
    From what I have seen so far, it seems that BooScript (.boo) and Python (.py) are relatively similar. My first language was Python, but for Unity I have been using C#, not Boo. I made an external Python map generator that outputs a matrix of points with different altitudes and terrain types, and I would like to import this into my game in Unity. However, I didn't use MonoBehaviour in my mapgen.py script. I have several classes with constructors using __init__ which seem not to register in Unity. Also, I can't seem to figure out how to use the BooScript debugger. Does anyone know how to convert Python to BooScript, and what the primary differences between the two languages are? I worked on my Python script for several weeks and would hate to have to do it from scratch again using C#/JS/Boo. Thank you for all your help!
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    1) boo is technically no longer supported. The compiler technically still exists (well in 5 it does, not sure about 2017), but it's considered obsolete.

    2) Since it's obsolete, as well as when it was active the boo userbase was tiny, there's not really anyone around here that still uses it.

    3) As for differences between boo & python, there are several articles on the internet. Here's one specifically from the boo github:
    https://github.com/boo-lang/boo/wiki/Gotchas-for-Python-Users

    4) One of the major hiccups you might have is that of the library. I don't know what libraries you used in your python script, but I doubt it accesses anything .Net or UnityEngine. That's the biggest critical difference is that boo uses the .net and Unity libraries. Not the standard python libraries. They're similar in syntax, not in library.
     
  3. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,033
    Boo was removed. Not sure how far back you need to go to find a version with support. And as said above, it's not Python and you won't be able to use any libraries which actually make Python worth a damn.
     
  4. ElnuDev

    ElnuDev

    Joined:
    Sep 24, 2017
    Posts:
    298
    Ah, okay. Would you suggest doing it all again in C#/JS? Thanks for the info, I was kind of wondering why there was so little information on Boo. :oops:
     
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    I would definitely suggest rewriting it in C#.

    What's the script look like? Can you share it?
     
  6. ElnuDev

    ElnuDev

    Joined:
    Sep 24, 2017
    Posts:
    298
    Thank you for the response. :) Shame Python isn't supported. Looking back, I believe all the Boo options disappeared when I switched from Unity 2017.1 to Unity 2017.3. Thanks!
     
  7. ElnuDev

    ElnuDev

    Joined:
    Sep 24, 2017
    Posts:
    298
    The original Python version outputed the result to terminal.
    Here is a shortened version (the whole thing is several hundred lines):

    Code (Boo):
    1.  
    2. # -*- coding: utf-8 -*-
    3. import random
    4. import codecs
    5. import math
    6. class city:
    7.     # SOME STATIC VARIABLES
    8.     def make_name():
    9.         # GENERATES RANDOM CITY NAME
    10. class bcolors:
    11.     # USED FOR ANSI ESCAPE CODES
    12. city_name_list = []
    13. class tile ():
    14.     def __init__(self, tile_type, dist, height, w, h, culture_point):
    15.          # A BUNCH OF DATA (ALTITUDE, ETC)
    16.     def getChar(self, isColor):
    17.          # OUTPUTS CORRESPONDING ALTITUDE CHARACTER
    18. def generateWhiteNoise():
    19.     # GENERATES MAP MATRIX
    20. print(bcolors.NORMAL)
    21. uniform = float(input("Uniform: "))
    22. width = int(input("Width: "))
    23. file_name = str(input("File name (without suffix): "))
    24. continents = int(input("Continents (max 8): "))
    25. if continents > 8:
    26.     continents = 8
    27. cities = str(input("Cities? y/n: "))
    28. if cities == "y":
    29.     cities = True
    30. else:
    31.     cities = False
    32. file = codecs.open("{}.map".format(file_name), "w", encoding="utf8")
    33. noise = [[r for r in range(width)] for i in range(width)]
    34. center_points = []
    35. for x in range(1, continents):
    36.     center_points.append(centerPoint(width, noise, x))
    37. generateWhiteNoise()
    38. print(bcolors.NORMAL)
    39. print("The following map has been saved to " + file_name + ".map.")
    40. print("There are " + str(len(city_name_list)) + " cities in " + file_name + ".")
    41. print(", ".join(city_name_list))
    42.