2015-07-12 23:36:02 (edited by brian.kurosawa 2015-07-14 14:03:15)

Hi, i have some questions about bgt. I want to make a game with events and pusles, but
i'm not sure if what i'm doing is correctly. I'm searching a
solution to do it withouth using hundreds and thousands of ifs.
I ve made a class called event, that are within a array on the map class, and when somethin happen, i call a function
at the map called check events, that call another function called check for each event at the array with a
user data string has parameter for both functions.
About using itens on another like a key on the door or a missing lever at somewhere, when it happens i call the check events function with on_use has parameter using both handled objects and
target object has parameters separated by commas. And to define what will happen are define at a string that the things
are separated by slash and the parameters of then are separated by commas too. Anyone knows a another way about doing it?

2015-07-13 17:12:15

Events as in scenes and such?
Perhaps you could place them on the map. For instance, you probably have a 2D array to represent your map, where you can walk and where you can't, etc. Perhaps you could add a secondary array the same size as your map which contains either some offset in to an array of event classes (or handles to event classes) on the squares for which events should trigger? This way when you take a step, you check that array and if an event should trigger where the player is standing, you fire it. Another approach is to just have an array of event classes which contain properties like their X and Y position and some active status flag. When the player moves you loop through them and activate if needed.

int events_length = events.length();
for(int I=0;i<events_length;i++)
{
//assume an event trigger zone is more than one square.
if(player.x >= events[i].left_edge&&player.x <= events[i].right_edge&&player.y >= events[i].bottom_edge&&player.y <= events[i].top_edge&&events[i].active)
{
events[i].trigger();
}
}

Lots of conditions, but only one if. You could wrap some of those checks up in a function if you want cleaner code but that's the general idea.

Official server host for vgstorm.com and developer of the Manamon 2 netplay server.
PSA: sending unsolicited PMs or emails to people you don't know asking them to buy you stuff is disrespectful. You'll just be ignored, so don't waste your time.

2015-07-14 03:41:07

I am confused about the show_game_window function.  Should I call this function before or after the main function?

Add me on Skype, search for The Evil Chocolate Cookie

2015-07-14 04:29:01

try within the main function. that could work. smile

If you have issues with Scramble, please contact support at the link below. I check here at least once a day, so this is the best avenue for submitting your issues and bug reports.
https://stevend.net/scramble/support

2015-07-14 05:48:23

About it i awready had a solution, events that i want mean is about using
a lever on a missing place to get a key, withouth using thousands
of if statements, because it may take a lot of time on this project that i'm
working on.

2015-07-14 07:59:32

@brian.kurosawa: I'm trying to understand what you want here. Do you want to implement an event-listener system / signals and slots design pattern?

If so, I recommend reading chapter 15 of Game Programming Patterns here:
http://gameprogrammingpatterns.com/contents.html

2015-07-17 20:09:58

Hi. I can't use if statement. Please help me! It's confusing! So, this is the example code.
string
my_name="John Doe";
int age=random(5, 50);
string message_string="My name is " + my_name + ", I'm " + age + " years old which means that I am ";
if(age<18)
{
message_string+="a minor!";
}
else
{
message_string+="of full age!";
}
void main ()
{
alert("Important information", message_string);
}
The bgt says compilation error, expected token 'if'. What can i do?

Hail, Daughter of Hatred. Creator of Sanctuary. Hail...Lilith.

2015-07-17 21:39:37

Move all of the code to intisde of the main function. You can't execute anything like an if statement etc outside of one.

Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.

2015-07-18 18:06:41

Hi!
I have problems with a code, The bgt says in the if ammo =0 line, but i don't know what is the problem. The void what is wrong is this:
void player_act()
{
if(key_pressed(KEY_LEFT) and player_position>0)
{
player_position--;
}
else if(key_pressed(KEY_RIGHT) and player_position < (board_size-1))
{
player_position++;
}
if(key_pressed(KEY_SPACE))
{
if(ammo = 0, false)
{
pool.play_stationary("click.wav");
}
if(ammo > 0)
{
shoot();
ammo--;
}
}
if(key_pressed(KEY_R))
{
pool.play_stationary("reload.wav");
int ammo=5;
}
if(key_pressed(KEY_ESCAPE)) // Exit game
{
lives = 0; // Simulate game over
}
pool.update_listener_2d(player_position, 0);
}

2015-07-19 06:42:24 (edited by Victorious 2015-07-19 06:43:38)

if(ammo = 0, false)

This assigns the value 0 to the ammo variable, and the comma followed by the false isn't a valid expression. What you probably meant is this:
if (ammo == 0)

2015-07-19 07:01:12

if(ammo = 0, false)

Is this supposed to mean "if ammo == any of (0, false)"?
Is there a programming language with that capability? It'd save a lot of typing. The best I can come up with is using python tooples like:
if (ammo in (0, False))

Since BGT is strongly typed, you don't need to worry about mixing up 0/false.
if(ammo==0)
Will do what you need.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2015-07-20 01:24:43

i wrote a turning sound for my game, but i have problem with the wait time, because it i don't use wait the game can't play my sounds. I use step.play_wait();, and i tryed step.play();

2015-07-20 01:56:44

And, an other question. I want music under my first and second level, but how i can do it?
I used
if(score<10)
{
gamemusic1.play_looped();
}
but it plays a lot in one second.
What can i do?

2015-07-20 08:09:24

Are you giving a chance for the sound to play? E.G if your application finishes execution or the variable goes out of scope, then your sound won't play.

Regarding your second post, this check for if (score < 10) is probably done multiple times a second. When the check succeeds, the music starts playing but then in the next game tick, its done again and the music starts playing from the beginning. You could fix this by checking the status of the sound. Something like this:
if (score < 10 && gamemusic1.isPlaying() == false) // i'm not familiar with BGT's api, but you get the idea.

2015-07-20 12:25:27

thanks, i will try it.

2015-07-21 13:43:58

i tryed it, but i thing i wrote something wrong, because it doesn't works.
I used this code:
if(score<10&&gm==false)
{
gamemusic1.play_looped();
bool gm=true;
}

2015-07-21 15:09:04

if(score<10&gm==false)

Check your punctuation. It should be rewritten as:
if (score<10 && gm==false)

bool gm=true;
This creates a new variable called gm. You probably meant to set the gm variable you already created to true. So the entire corrected code should look like this:

if (score<10 && gm==false)
{
gamemusic1.play_looped();
gm=true;
}

2015-07-21 23:51:01

Thanks for the help.

2015-07-22 00:37:27

an other question. The bgt help wrote an example for some birds, but i started from virus attack. How i can i add more viruses?

2015-07-22 01:01:33

Hi! I have a very annoying problem with BGT! I creating a menu-based game, where your decisions makes the story. And i using wariables to make the game more exciting. My problem: When i made a wariable for randomize some numbers, the wariable randomizing it once in the program! What can i do?

Hail, Daughter of Hatred. Creator of Sanctuary. Hail...Lilith.

2015-07-22 05:23:39

@arnold18: please be more clear on what you mean. Do you mean that you want a variable to contain a random number?

2015-07-22 07:28:37

dzsoker wrote:

i wrote a turning sound for my game, but i have problem with the wait time, because it i don't use wait the game can't play my sounds. I use step.play_wait();, and i tryed step.play();

I don't understand what you want mean but if it is what i'm thinking probably you should try avoid using wait/play_wait and try a timer instead.

2015-07-22 15:34:48

I don't want wait time. I added a reload sound for a weapon but until it's playing the enemyes are stopped, and it's don't real big_smile

2015-07-22 17:39:12

When your ennemies die/are stopped/etc., tell them to stop their sounds. smile

2015-07-22 19:13:11

I solved my problem.

Hail, Daughter of Hatred. Creator of Sanctuary. Hail...Lilith.