2018-01-10 06:23:40

Damned if this doesn't confuse the crap out of me no matter how many times I read the relevant sections in the documentation, or study the examples. Well, I will never be a talented programmer, this I know, and accept, but I want to be able to do this. I've asked in the skype group and got help there a bit but I still can't figure the thing out.

What I want to do is be able to use the tone_synth object, I want to have a function that generates the data I specif and loads it into memory by use of the write_wave_sound. Yes, I know I can just make the file and that makes things a lot easier, but that's not what I want, and that teaches me nothing because I already know how to do it. I just don't get handles at all. I don't get what the point is of them, if I had to guess, I would say it might be something like in C# how you have static vars vs abstract or whatever they call it, but I'm not sure about that.

So here's what I need:
- the reason you use them at all
- what they do
-how to use them, with examples, and if someone could help me more privately if I can't figure this out on my own.
- how to pass a handle from this sound object into other functions I've created.

I'm making a little tool off of Colton's thing he did on twitter. I want to code the thing myself, and do as much of it as possible, but I need help with this part, once I've got this down I'm straight, I can manage the rest.

The bipeds think this place belongs to them, how cute.

Thumbs up

2018-01-10 06:55:59 (edited by Amit 2018-01-10 06:57:43)

at first I did not get handels in bgt at all. I had same questions and here is what I've found:
handels are pointers to an object. if you wanted to make a function which will decrease the volume of a playing file you would use handels in the following way:

void volume_manager([email protected]_object) {

// here my_object is a handle. when you will call this function you have to pass something which is an object of sound class because the function requires it.
// read on, things will become clear
if (key pressed(page up) {

fade(my_object);//fade so that we don't decrease the volume abruptly

else if (key pressed(page down) {
// same code goes here, but this time for increasing the volume

we are done. now that function can be called in a gameloop and it can increase/decrease the volume nicely when page up or page down are pressed. note that we could have never done this if we were to pass a filename. we had to pass an actual object of sound class. that's why and how handles are used.
I might not have explained properly; in that case someone more experienced than me will try for sure.

There once was a moviestar icon.
Who prefered to sleep with the light on.
They learnt how to code, devices sure glowed,
and lit the night using python.

Thumbs up

2018-01-10 07:45:20

I'll have to study it when I am a little more awake. Most things, I might not get it through the doc alone, I might have to play with it a bit, but there's like this 'aha' moment, where the light bulb comes on, ya know? like oooooooh, that's how that works... I can't get there with handles, I can't get a handle on handles lol.

The bipeds think this place belongs to them, how cute.

Thumbs up

2018-01-10 07:52:11

To be honest? I don't see the point, either. This makes sense for low level stuff, like passing around pointers for ints in C, but BGT would be just fine—nay, better off—if it was just assumed implicitly that a reference to an object is it's handle unless there is explicitly an oppAssign method defined. When would you not use handles? It's derived from C, sure, but in practice, all it does is make for extra typing and more tedious porting.
Compare with Java, where all objects are treated as pointers, all primitives are treated as values, and references and syntax and dotting are accordingly simplified. (Except for Strings, but those are always special cases.) I think the majority of the time spent porting my games from Java to BGT was arranging all those @ signs, and parentheses, because how do those fit into order of operations, anyway? And the main thing holding me back from porting BGT games to other languages is that I'd have to either write a script to remove every single @ and its parentheses, or do so by hand. ... Also how Python made the terniary operator b if a else c, and everyone else ever made it a? b : c, but I digress.

So, if you're using objects in BGT, use @ signs. An array of objects? [email protected][]. A function that takes/returns objects? [email protected] myfunc([email protected] param). Class properties? @. Comparing objects? @[email protected] Dictionaries? Use @ even more. BGT dictionaries are in desperate need of wrapping in something less cumbersome.
The only weird thing is that you can do this: @a=b, or call that function from earlier like @a=myfunc(b). So I guess you only use @ on the right side for comparisons and dictionaries? Why? I don't know, but those operations do seem kinda special in this regard, so whatever.
Basically, you have to say @a=b, because just a=b tries to change a (the object). Except you can't do that anyway without opAssign, because BGT objects are not C-style structs, so there is no default for a=b. You're almost never working with objects directly, just pointers. It's through properties and methods that you can affect the underlying data,. You'd think this would mean you would only need the @ for opAssign, but I did not develop Angelscript and I do not know C++ and I'm probably missing something obvious to a CSmith.

So. Your example.
[email protected] mysound=synth.write_wave_sound();
Or if you're assigning it to a pre-existing sound:
[email protected] mysound;
This is why BGT desperately needs a the "new" keyword, or some equivalent. either that, or to just throw the handles under the hood. -_- 
Even better: vectors do not take handles well. So they work more intuitively, unlike sounds or dictionaries.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up

2018-01-10 23:39:56 (edited by ironcross32 2018-01-11 05:48:35)

Yeah seems kind of stupid to me to be honest.

Well, I did get it working, but I doubt I really understand what's going on, I think I just tried a bunch of stuff until something went right for a change lol.

The bipeds think this place belongs to them, how cute.

Thumbs up