2019-06-03 20:20:43

Hello! I read the how to use sound_pool in bgt, but i get this error... Here is the code and the error:
#include "dynamic_menu.bgt"
#include "sound_pool.bgt"
void main()
{
tts_voice voice;
show_game_window("Hamburger");
dynamic_menu menu;
menu.add_item_tts("Start the adventure");
menu.add_item_tts("achievements");
menu.add_item_tts("exit");
int choice=menu.run("choose an option from the menu",true);
if(choice==1)
{
game();
}
}
void game()
{
sound_pool poool;
int player_x;
int player_y;

while(true);
{
poool.max_distance =50;
poool.play_stationary("music.wav",false);
if(key_pressed(KEY_RIGHT))
{
player_x>1;
player_y>2;
poool.update_listener_2d(player_x,player_y);
}
else

{
alert("error!","An error occurred");
}
if(key_pressed(KEY_LEFT))
{
player_x<1;
player_y<2;

}
}
}

File: C:\Users\marco\Desktop\furia\furia.bgt
On line: 17 (1)
Information: Compiling void game()

File: C:\Users\marco\Desktop\furia\furia.bgt
On line: 29 (9)
Line: player_x>1;
Warning: 'player_x' is not initialized.

File: C:\Users\marco\Desktop\furia\furia.bgt
On line: 30 (9)
Line: player_y>2;
Warning: 'player_y' is not initialized.

Best regards: Marco

Thumbs up

2019-06-03 20:52:34 (edited by goran 2019-06-03 20:54:21)

Hi,
I haven't worked much with bgt, but from the look of things it appears that you have only declared the player_x and player_y variables without giving them any value. Try int player_x=0, player_y=0; , or whatever value you need the variables to be initially.
also i don't know what you mean by player_x>1; and player_y>1;
do you want to increase their value by 1? If so, you should do player_x++;
player_y++;
same goes for the left arrow, instead of writing player_x<1; write player_x--;

Thumbs up

2019-06-03 22:28:35

You can do something like int x;, but you need to declare a variable for it before using it. So the easiest way is to do something like int player x = 1;
As also stated above you can not use < and > to adjust the value of a variable.

My name is Inigo Montoya. You killed my space bar. Prepare to die!

http://l-works.net

2019-06-04 16:34:18

As everyone said, you can't do player_x>1; you must actually do player_x-=1; or player_x--;
-- and ++ increase and decrease the value by 1 and is recommended to use these unless you need to increment the value by more than one, at which point you'd do player_x+=3; or player_x-=3; respectively. Hope this helps!

Follow on twitter! @masonasons_me
Thanks, enjoy, thumbs up, share, like, hate, exist, do what ya do,
my website: masonasons.me
If this post is of any use, why not thumb it up?

2019-06-04 17:36:35

and it's probably not smart to have poool.update_listen_2d in the moving code, here is how I would do it.
Please note: this might not work, but you know...

I'm starting at void game. Instead of declaring those variables in void game, declare them at the top. I would also prepose using a vector instead of ints, but that's just me...

void game()
{
p.play_stationary("music.ogg",true); //set this to true so that it loops
while(true)
{
wait(5);//give windows time to breathe
p.update_listener_2d(me.x, me.y);//now it will just constantly update, just in case you have something like an item or a teleporter that moves you randomly.
if(key_pressed(KEY_RIGHT))
{
me.x++;
me.y++;
p.play_stationary("step.lol",false);
}
//same for left arrow.
}
}


Remember, don't copy my code directly haha.
yo! so I'm working on programing, it's really hard. But I'll tell you where you can contact me if your stupid enough to do so.
Contact information:email: [email protected]
Skype: Brennan Draves
I'm usually found on online games, chatting, and being warned bye admins for talking to much, f**k you admin!

2019-06-04 23:54:10

I actually have the update listener method called when moving as why else would you ever need to update a listener?

My name is Inigo Montoya. You killed my space bar. Prepare to die!

http://l-works.net

2019-06-05 03:14:51

Updating listener in the main loop becomes useful when using a teleporter and preventing movement.  The update  method is also useful if your game is stationary, like sound RTS.  That said, Liam’s logic will work 99% of the time. Even the first case can be negated by calling the move method, assuming that it takes a value which  dictates the direction a player must move as it’s  parameter.

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-06-05 03:21:42

The rule of thumb is to never call update unless something has changed. if an object moves, naturally there need to be updates sent, so your object should make a call to update. By calling update when nothing has changed just wastes resources and can actually degrade performance. I had this when first coding Super Egg Hunt. Now I only call update on player and chicken movement

My name is Inigo Montoya. You killed my space bar. Prepare to die!

http://l-works.net

2019-06-05 13:09:33

That does make sense, but I'd probably do it in my games, at least the bigger ones, because there's usually something moving constantly, and I don't want to have to call p.update_listen_2d for every class movement thing.

yo! so I'm working on programing, it's really hard. But I'll tell you where you can contact me if your stupid enough to do so.
Contact information:email: [email protected]
Skype: Brennan Draves
I'm usually found on online games, chatting, and being warned bye admins for talking to much, f**k you admin!

2019-06-05 15:01:24

Again. You will negatively impact performance.
If you code in a modular fashion you should only have to add one call in your class.

My name is Inigo Montoya. You killed my space bar. Prepare to die!

http://l-works.net

2019-06-05 15:52:58

Hmm, I've been doing it for a while and never once saw a drastic drop in performance, although it does make sense.
But just imagine that:
I have several different enemies, all with different moving speeds, all moving in different posisions.
If i have some enemies in a separate class, I'm going to have to write the update function for all the classes.

Normally I wouldn't write them separately, but if I have many different kinds of enemies, I might.

yo! so I'm working on programing, it's really hard. But I'll tell you where you can contact me if your stupid enough to do so.
Contact information:email: [email protected]
Skype: Brennan Draves
I'm usually found on online games, chatting, and being warned bye admins for talking to much, f**k you admin!

2019-06-05 15:56:37

Isn’t update_sound a thing? That’s what you can use instead of update listener, assuming that everything is not stationary.

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-06-05 16:46:08 (edited by redfox 2019-06-05 16:47:40)

no, update_listen,2d is coded like this:

 p.play_2d("sound.wav",listernx,linstenery,targetx,targety,looping); 

so, if you didn't update this, your focus would not move, and you would here yourself walk away. But if you call the update after you play a step sound or after you move, you may warp out of focus for a tiny second.
If you call it in the while loop, then it will always be on your tile.Y

yo! so I'm working on programing, it's really hard. But I'll tell you where you can contact me if your stupid enough to do so.
Contact information:email: [email protected]
Skype: Brennan Draves
I'm usually found on online games, chatting, and being warned bye admins for talking to much, f**k you admin!

2019-06-05 17:29:38

as long as you call update_listener when teleported you'll have no problems.
if you have sounds that move, like enemies, you'd use update_sound on those.
I can guarantee with a great degree of accuracy that too many calls will degrade performance.

My name is Inigo Montoya. You killed my space bar. Prepare to die!

http://l-works.net

2019-06-05 20:11:53

I may have to try that in another project. Fox, when are you calling update listener, Before you move the player or after?  make sure to play steps after the update listener method has been called, unless your steps are stationary.  on a slightly unrelated note. When working with multiple types of enemies, you should still have one loop for them.  I use a combination of if statements and function calls to check for any special behavior that should occur whenever a target moves or whenever enough time has elapsed
Liam, if I want to track the drop in performance, how would I go about doing so?  Also, to clarify, you are only updating the sound via update_sound method whenever something moves, not every single iteration of the loop, correct?

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-06-06 03:49:27

Correct. I only update a sound position if that sound actually has moved.
For stationary objects you shoud never have to update their sounds. Also by stationary I'm referrign to an actual object that makes sound, not the actual stationary play functions.
I can't think of a good method off the top of my head to check for degraded performance, but if you follow those tips you should never ever have any issues.
When I first converted Super Egg Hunt, I had 200 eggs constntly updating their sound pool position on each loop. The game slowed to a crawl, and I couldn't figure out why at first. It was pretty simple. I was calling update-sound 200 times for every loop iteration.

My name is Inigo Montoya. You killed my space bar. Prepare to die!

http://l-works.net

2019-06-22 17:52:52

I'm sorry to be thread necro again but... Liam, how would you deal with updating sound ranges? Same thing, only when listener moves or what? The sources in question are stationary.

Coding is not hard. No, not at all.
What is hard is making code that accepts different and sometimes unexpected types of input and still works.
This is what truly takes a large amount of effort on a developer's part.

Thumbs up

2019-06-24 16:19:35

same thing. if the source isn't moving, there's no reason to update it.
And in sound pool you should only have to update the listener and not any of the sources.
if source moves, update source.
if listener moves, update listener.
Never randomly update things because you can.

My name is Inigo Montoya. You killed my space bar. Prepare to die!

http://l-works.net