1

Hi, I have some questions about bgt.
What is uint and how does it work?
And what is i, and can I have some examples of using these?

Thumbs up

2

High,
In BGT, there are several different data types and several different types of data types. Yes, I know -- that sounds confusing. A data type is a classification of data which tells the compiler or interpreter how the programmer intends to use the data. Data types are also known as just 'types'. There are many different types, all differing for each programming language you use. However, since your asking specifically about BGT, I'll outline those for you:
BGT has several different types. These are int, uint, short, long, ushort, ulong, void, string, float, and double. Then there are the bit-constraint types: int8, int16, int32, uint8, uint16, and uint32. The int, short, long, uint, ushort, and ulong types are aliases for int32, int16, int32, uint32, uint16, and uint32 respectively. The types with the 8, 16, and 32 as their suffixes are the number of bits within each type: 8-bit integers are within the range -128 to 127; 16-bit integers are within the range -32768 to 32767; and 32-bit integers are within the range -2147483648 to 2147483647. Then there are the unsigned versions of these types. This is where things get drastically different: unsigned types cannot -- and I stress the word cannot -- be negative. The unsigned 8-bit integer is within the range 0-255; the unsigned 16-bit integer is within the range 0-65535; and the unsigned 32-bit integer is within the range 0-4294967296. (Newer programming languages have added int64 and uint64; with int64 being within the range -9223372036854775808 to 9223372036854775807 and uint64 being within the range 0-18446744073709551616, but BGT is not this up-to-date). I hope this clears up your first question.
Examples of these types being declared:
int hello; // same as int32 hello;
uint hello2; // same as uint32 hello;
Or, initializing them with a value:
int hello = 525; // same as int32 hello = 525;
uint hello2 = 3394891847; // same as uint32 3394891847;
etc.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

3

To explain why you might want to use int8 or uint8 instead of int or uint:
A bit can either be on or off, so 0 or 1. So with 1 bit, you have 2 possibilities: on or off.
With 2 bits, you have 4 combinations: (0,0) (0,1) (1,0) (1,1). with 3 bits you have 8 combinations, which is also 2^3. With 4 bits you have 16 combinations, or 2^4. int8 has 8 bits, so you can do 2^8 = 256. Now I don't remember exactly, but this probably means that int8 can have values from -128 to 127. When we have 16 bits, much more combinations become available, 2^16 = 65536. But why would you ever use int8, int16 when you have int32, well, int8 or int16 will only have a small advantage when you have a very, very large number of them that need to be compared to other values. So for example, if you have a game board: it is a square 1000*1000, so it has a total of 1000000 squares. If 0 stands for a wall, and 1 stands for a walkable tile, and you want to make a list of all walkable tiles, it will be much faster comparing the 8-bit values to 1, then to do the same for a 32 bit value. Will it make a world of difference? no. It's just a small thing you need to think about, but if you're just starting out, you can safely ignore int8, int16 and uint and come back to them later when you have learned while loops and that sort of stuff. If you already have some more experience, you should be able to understand it now.

Roel
golfing in the kitchen

Thumbs up

4

BGT does have a type definition for int64. I know because I've used it.

Thumbs up

5

@Jason SW, so then it would have the appropriate ranges I've specified. Does it have a typedef for uint64, though?

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

6 (edited by Jason SW 2017-03-18 22:18:36)

It does have both int64 and uint64. However... After some testing, I found that they don't actually act like they should! Maybe the AngelScript engine has support for them, but since BGT was never compiled for 64 bit machines, it can't actually use them.
Int64 just acts like a regular int, and uint64 acts like a regular uint.

Thumbs up

7

Hi. I think i got your point. King zombie. I is a variable. Like this:
uint i;
But, I'm almost sure that you've seen something like this and you got this question shining in your mind:
for(uint i=0; i<something; i++)
And in this case, I have to tell you that this is a for loop. These loops are used to access arrays elements, or repeat something for some amount of time. And here, "I" is a variable which used the "uint" datatype.
Learn more about for loops and other loops at the bgt's language tutorial, under bgt manual file (bgt.chm).

Be careful that what you're saying, Just a word Can break your personality!

Thumbs up

8

I have another question, I was trying to play a sound looped with the sound_pool. I typed, p.play_stationary("sound.ogg",true);
when I run the script the sound plays, but it sounds like it is playing more then once. How can I fix this

Thumbs up

9

Hi,
You'd have to submit the code surrounding that statement for us to help you there. sound_pool.play_stationary has the declarative form of:
int play_stationary(string filename, bool looping, bool persistent=false)
(see remark 1 below for information.)
You might want to try sound_pool.play_stationary_extended (), which has the declarative form of:
int play_stationary_extended(string filename, bool looping, double offset, float start_pan, float start_volume, float start_pitch, bool persistent=false)
(See remark 2 below for information.)
Here is the parameter listing for play_stationary();
filename
The filename to play.
looping
A boolean specifying whether the sound should loop or not.
persistent
An optional boolean specifying whether the sound should be persistent or not, meaning whether or not it should be automatically cleaned up after playback has finished. If this argument is not given, false is the default which means that the sound does get cleaned up.
And here is the one for play_stationary_extended:
filename
The filename to play.
looping
A boolean specifying whether the sound should loop or not.
offset
The point in the sound file where playback should begin, in milliseconds.
start_pan
The starting pan of the sound.
start_volume
The starting volume of the sound.
start_pitch
The starting pitch of the sound.
persistent
An optional boolean specifying whether the sound should be persistent or not, meaning whether or not it should be automatically cleaned up after playback has finished. If this argument is not given, false is the default which means that the sound does get cleaned up.
Remarks:

  1. This method is useful for playing sounds such as the listener's footsteps, game ambiences, etc. A sound that is created with the persistent flag will not be cleaned up after it has finished playing, which otherwise is the default behavior. Instead, an explicit call must be made to destroy the sound. This is useful for non-looping sounds that you wish to be able to reliably manipulate with any of the functions that use slots to identify a particular sound. When set as persistent, a sound slot is guaranteed to stay valid regardless of playback status. This also means that you must be sure to destroy it when it is no longer in use, as that slot will otherwise be locked and not available for reuse by new sounds.

  2. Reuse of remark 1.

Examples for play_stationary:

#include "sound_pool.bgt"

sound_pool sound_environment;
timer walk_timer;

int player_position;
int step;

const string sound_extension=".wav";

const int left=-1;
const int right=1;

const int boundary=200;

void main()
{
show_game_window("sound_pool test");
sound_environment.max_distance=70;
for(int counter=1; counter<15; counter++)
{
sound_environment.play_1d("sounds/sound"+counter+sound_extension, 0, random(0, boundary), true);
}
while(true)
{
check_input();
wait(5);
}
}

void check_input()
{
if((key_down(KEY_LMENU))&&(key_pressed(KEY_F4)))
{
exit();
}
if(key_down(KEY_LEFT))
{
walk(left);
}
if(key_down(KEY_RIGHT))
{
walk(right);
}
}

void walk(int direction)
{
if((direction<=left)&&(player_position<=0))
{
return;
}
if((direction>=right)&&(player_position>=boundary))
{
return;
}
if(walk_timer.elapsed<350)
{
return;
}
step++;
if(step>6)
{
step=1;
}
walk_timer.restart();
player_position+=direction;
sound_environment.play_stationary("sounds/steps/"+step+sound_extension, false);
sound_environment.update_listener_1d(player_position);
}

And here is one for play_stationary_extended:

#include "sound_pool.bgt"

sound_pool sound_environment;
timer walk_timer;

int player_position;
int step;

const string sound_extension=".wav";

const int left=-1;
const int right=1;

const int boundary=200;

void main()
{
show_game_window("sound_pool test");
sound_environment.max_distance=70;
sound_environment.play_stationary_extended("sounds/ambience"+sound_extension, true, 500, 0, -1, 90, false);
for(int counter=1; counter<15; counter++)
{
sound_environment.play_1d("sounds/sound"+counter+sound_extension, 0, random(0, boundary), true);
}
while(true)
{
check_input();
wait(5);
}
}

void check_input()
{
if((key_down(KEY_LMENU))&&(key_pressed(KEY_F4)))
{
exit();
}
if(key_down(KEY_LEFT))
{
walk(left);
}
if(key_down(KEY_RIGHT))
{
walk(right);
}
}

void walk(int direction)
{
if((direction<=left)&&(player_position<=0))
{
return;
}
if((direction>=right)&&(player_position>=boundary))
{
return;
}
if(walk_timer.elapsed<350)
{
return;
}
step++;
if(step>6)
{
step=1;
}
walk_timer.restart();
player_position+=direction;
sound_environment.play_stationary("sounds/steps/"+step+sound_extension, false);
sound_environment.update_listener_1d(player_position);
}
"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up