Using Unity3d like Blitz3d

Community Forums/General Help/Using Unity3d like Blitz3d

RemiD(Posted 2013) [#1]
Hello blitzers, :)

Sorry to be so old school but i like my old habits of having to use one main code file and to include several others code files at the top of the main file and then to create|control|destroy everything by code.

I have already made several attempts in 2011 to use Unity3d like Blitz3d but i had gave up due to the complexity of the syntax.

I'm back ! Not by choice but more because i see Blitz3d seems to have and will have more and more compatibility problems with windows 8 and the next windows OS.

I have followed some tutotials to learn more how Unity works and how to code.

At the moment i use this organisation :

->One scene with only one GameObject named "Master".
->One script named Main.js attached to Master, it will contain the main initialisation Start(), the main logic1 loop Update(), the main collision detection and response OnCollision(), the main logic2 loop FixedUpdate(), the main GUI commands OnGui()
->One script named G.js attached to Master, it will contain all global variables, all global entities (including the camera), all global arrays, all global functions (all the Blitz3d functions so that it simplifies the syntax that i have to type)
->One script for each kind of entity named Entity.js, for example for Player, the script will be named Player.js, for Bots, the script will be named Bot.js, for Rooms the script will be named Room.js.
Each entity script will contain all the variables, all the entities, all the arrays, all the functions concerning this kind.

I will create|modify|control|run|destroy all variables, all entities, all arrays, all functions from the Main.js.

To access|read|write a variable :
Bot.Name
Bot.Energy
Bot.Life

To access|position|rotate|turn|move an entity (GameObject)
Bot.Pivot
Bot.Mesh

To access|read|write a variable in an array :
Bot.Name[1]
Bot.Energy[1]
Bot.Life[1]

To access|run a function :
Bot.Sense()
Bot.Think()
Bot.Act()

I have seen that i can access other script and variables, entities, arrays, functions of other script by using 2 ways, either declaring all variables, entities, arrays, functions as static, or by declaring them as public and then retrieving the reference of the script.

So all seems to work as i want even if the syntax is a bit more complicated but if i can use Unity3d this way, this is good enough for me.

I don't understand how some programmers like to use one script attached to each entity, for a simple app|game, it may be easy enough to do that, but for a complex app|game, it must be really confusing to remember what script does what and to correct the errors.

My only worry at the moment is how i will be able to create|destroy a collider by code, how to retrieve the infos of a collision between 2 colliders, and if i will be able to reposition the collider at the right position without messing up the collision engine. This was my failure the last time. Anyway i will see how it goes.

If you use Unity3d and you like to create|control|destroy everything like with Blitz3d or with BlitzMax, how do you organise your stuff ?
I am curious.

Thanks,


Yasha(Posted 2013) [#2]
Using a script attached to each entity is just OOP in action. Once you get used to it you'll find it really is the much, much easier way to code.

Think of it this way: the script (the stuff-to-do for each entity) has a de facto existence whether you code it in or not, or the entity won't actually work. You can either attach it to the entity directly, or you can implicitly attach it to the by virtue of the fact that the control calls activate when you trawl through the confused mess of main update code; but the code exists and applies itself to the entity either way.

So why not reflect what's actually happening in your design, instead of writing "by implication" and just exposing the machinery rather than what you actually want to do?

It's got the huge advantage of focus: when you want to work on what an entity does, you can work on what an entity does and nothing else; and also of maintainability and expandability: you can use this focus to both mod existing entities and rapidly add whole new ones to the fray.

The reason it seems complicated is because you're trying to use it like B3D: B3D can't express a lot of these design patterns and therefore they seem complicated. The truth is that it's the other way around - maintaining a medium-large project in B3D is a nightmare because that same monolithic design you're looking at really makes it nearly impossible to keep your code organised once you pass the ~40KLoC barrier. I'd go so far as to say that this "style" is probably the single biggest reason nobody ever finishes anything in B3D.


If you want advice, here's what I would recommend doing, in order (this is a sequence of steps):

0) (step away from Unity for a week or so while steps 1-3 sink in, use other tools)

1) learn OOP. Understand polymorphism fully. Read and understand other object-oriented game architectures.

2) learn about and fully understand callbacks. Make sure to understand the difference between a function pointer, a callback, a delegate and a closure, and how one can be used to build the others. Read up on introductory FP. Make sure you fully understand functions as values (something alien to BASIC)

3) learn JavaScript properly. JavaScript is a subtle and powerful language and learning to program in B3D will not have helped you master it to any significant degree. JavaScript is nothing like B3D, nor for that matter is it anything like BlitzMax, Java or C. (It's closest to a mix between Scheme and Self.) You need to understand JavaScript's prototype-based object model and its function-objects at the very least.

4) armed with a proper understanding of JavaScript, go back and architect your Unity program according to the Unity JS tutorials; you should by this point be able to take advantage of the structure they designed e engine for and will enjoy using it a whole lot more.


TL;DR: the JavaScript way is objectively superior to the B3D way, there is a reason why people use it; if you use the B3D way you will be ignoring most of the power of JS and by extension Unity; learn to use the tool in the way it was designed; do not assume that JS is as weak a language as B3D, or that they B3D design is any good, just because that's the way you know how to code at the moment.


I'm sorry that came off as my usual arrogant and didactic rant but the big problem here is that you are engaging in the classic Paul Graham "blub paradox": assuming that the way you code now in a weak and unstructured language is the right way to code everywhere and therefore ignoring the much better ways to code opened up by much more powerful languages, instead assuming they are worse because they aren't receptive to your less powerful coding style.

I should also point out again tht this is mostly a JS vs. B3D issue, and the fact that you're using Unity is mainly relevant in that Unity can be used from JS. (It is a legitimate problem that people act like JS is suitable for beginners and artist when it clearly isn't, but that's another story.)


Alternatively, don't use the complicated language that is JavaScript, and instead stick to the comparatively simple language option that is C#: this is closer to what you know, uses a much less alien object model, and should make it much more obvious how all of these things work after about step 2 on the above list.


RemiD(Posted 2013) [#3]
I see no point to learn OOP at the moment, i have read some code examples in some tutorials and in Unity answers, and what i see is that they type more code to do the same thing that i do in Blitz3d with less code.



FYI, the only reason i have not finished a complex game until know is not because i don't understand how to do it, or because i am lost in my code, it is because i had to do others works to earn enough money to cover my expenses. And also an existential problem, why spend time making or playing games ? But this is another topic.

If all goes well, i will have more time to code soon.




do not assume that JS is as weak a language as B3D, or that they B3D design is any good, just because that's the way you know how to code at the moment.


I do not assume it is weak, i partly understand how it works, but again i see no point to type more code to achieve the same thing.

My goal is to make a game, not to have a trendy code.




assuming that the way you code now in a weak and unstructured language is the right way to code everywhere and therefore ignoring the much better ways to code opened up by much more powerful languages, instead assuming they are worse because they aren't receptive to your less powerful coding style


No i assume that, as in every field, there are trends and some people like to follow, some people don't.
I am not against OOP, i just don't see why i should use it if i can achieve all i want with the way i code and with less code.

The idea to have to type the Pointer (i guess it is a pointer) of a class before a variable, a gameobject, an array, a function, just to access it, already annoyed me. So if you ask me to type a long instruction only to read a variable, i will have difficulties to understand how it is more efficient. More stylish maybe.

But you are probably right, my mind has so been shaped by the Blitz3d coding way that now i can't grasp the advantages of others langages.
However this does not change my goal : to make a game.

I guess each one has his preferences.
And maybe if i keep reading and using this langage, after some time i will effortlessly be converted to this new way of coding.


Kryzon(Posted 2013) [#4]
Hi, good idea for a thread.

This here seems relevant:
http://blitzbasic.com/Community/posts.php?topic=94320 (if not for using the actual framework, at least for getting to know how the Blitz3D functions translate to Unity .js code).


RemiD(Posted 2013) [#5]
Yes blitzlike is a good base to understand how to find the right Unity commands corresponding to the Blitz3d commands but the collisions system does not work properly (from the tests i have done in 2011).
Maybe i will manage to fix it this time.

Also i have others ideas of functionalities that i want to add. Like the concept of Colliders which are either Pickable or NotPickable and Collidable or NotCollidable.

We will see how it goes.


patmaba(Posted 2013) [#6]
Hi everyone,

I'm coming late on this post.

I am surprised that we are talking about blitzlike. I have not continued the project. In 2011, there was not a lot of people interested in my blitzlike project.

I did not continue and develop this library.

The origin of this project blitzlike was to trying a convertion of my projects from Blitz3D to unity.

I needed a bridge.

So I started coding a minimum lib and then was born blitzlike.

I stop my dev during collision detection system where wrapper function was very difficult to implement.

sincerely

patmaba


jfk EO-11110(Posted 2013) [#7]
I can js!
alert(" nobody ever finishes anything in B3D.")
ERROR!!! MISSING SOMETHING!!! PLEASE REBOOT.
alert(" nobody ever finishes anything in B3D.");
ERROR!!! MISSING OBJECT IDENTIFIER!
localhost.os.explorer.msie.window.document.frame.table.alert(" nobody ever finishes anything in B3D."); 
Will try to compile on the fly...please get coffee...
 

I wish somebody would finish windows. or android. before it's released, delivered and sold.
Seriously, shure there are more powerful languages. But if you want a ride with a beach buggy, do you need a ferrari engine?
What really scares me is how powerful AI can become, using OO Code and complex modules. luke, eg. a troyan may use any possible way to connect, luke some hacks to remotely activate a hotspot of a nearby smartphone, etc. And the main code only has to say "connect somehow". That's where powerful becomes power becomes danger... oh no, I just went from code to politics , gotta sleep ;)


Yue(Posted 2013) [#8]

alert(" nobody ever finishes anything in B3D.")
ERROR!!! MISSING SOMETHING!!! PLEASE REBOOT.
alert(" nobody ever finishes anything in B3D.");
ERROR!!! MISSING OBJECT IDENTIFIER!
localhost.os.explorer.msie.window.document.frame.table.alert(" nobody ever finishes anything in B3D.");
Will try to compile on the fly...please get coffee...



Your comment makes me laugh, programming itself is very easy in Blitz3D, however make a video game it's crazy, it will eventually lose the naivety and most failures with Blitz3D, is that users have come programming in this engine, I mean most are novice fans, but the truth is that if you can have some money and buy the talent of others to the modeling, music and things like that Blitz3D would be great for a small team.

Now the weird part is that paranoia again has been reborn and is no longer with Windows 7, if not with Windows 8 and this at the end for an inexperienced user takes to not rely on a lack of knowledge Blitz3D.

We sold the best game in the world with Blitz3D, pretend to be programmers, but it is really important to understand that one person does not make a video game, of course if you want to secure squares will.

Greetings.


*(Posted 2013) [#9]
Ya could write a script to do everything that Blitz3d could do using Unity script however it would be quite a long winded process to do it though :)