2018-02-03 17:12:56

Hi, everyone.
While I was playing with BGT a little, and wanted to implement something, I've realised that I have no idea how to do it.
To be honest, I have more ideas of ways to implement what I want, but I'm not sure at all what to do... I'll explain bellow what I'm doing.
So, I've created a menu with several characters where you can choose from.
If you choose a character, the string character will get a particular name, and depending on what character you have chosen, it will perform different actions, if you press A, S, or D keys on the keyboard.
Because each character has different skills and techniques, I made a function which is checking what character you have, as a result, each character will perform his specific action.
The problem is that I know how to make it work if I'm using just one key, and each character has just one skill.
But, what to do if each character is having 3 assigned key, so in short, 3 uniques skills?
I'll let you know what I made so far below.
void lupta()
{
while(true)
{
if(key_pressed(KEY_A))
{
character_checking();
}
if(key_pressed(KEY_S))
{
character_checking();
}

void character_checking()
{
if(character=="Michael")
{
fighter.play_wait();
fighter1.play();
}


As you can see, I put in the code only one technique, but my character has 3 skills by pressing A, S, D, and I have 3 or 4 different characters with their own skills.
How to make the program to check it properly in the easiest way properly?
Should I use classes, or what metod would you recommend?
If it would have be using just one skill for each character, so, just one key, it would be really easy.
But now, with multiple characters and each one having 3 different skills, I really don't know how to make the script to check the character when I'm pressing the above mentioned keys.
Sorry that the post is the long, but I wanted to explain it as detailed as I call, although I'm sure it will need more explaination later.
Hope to get some info about this issue.
Thanks in advance.

2018-02-03 18:51:47 (edited by targor 2018-02-03 18:55:20)

The Problem is that you put your skill Code in the character_checking function. Instead, alter it so that character_checking hasn't type void, but type string and that no skill usage Code is inside. Then the only Thing this function does is return the character string and nothing more. Now in your other function, you can ask something like "if (character_checking() == "Michael")" and put your skill Code in the if branch. Now you can make nested if branches, like
if (key_pressed(KEY_A) {
    if (character_checking() == "Michael") {
        Code here
    }
}

Hope that helps.

We are pleased, that you made it through the final challenge, where we pretended we were going to murder you. We are throwing a party in honor of your tremendous success. Place the device on the ground, then lay on your stomach with your arms at your sides. A party associate will arrive shortly to collect you for your party. Assume the party submission position or you will miss the party.

2018-02-04 04:44:02 (edited by nyanchan 2018-02-04 04:46:05)

The smartest way would be using polymorphism, but if you don't want to deal with classes, you just could pass the pressed key to the character_check function.
As I observed, making character_check so that it just returns the character you're using is completely pointless because the character string can be accessed anywhere from the script in your context.
Also, if you are actually going to do that, character_check should be renamed to character_action or anything else that can well descrive the behavior of the function.

I don't speak as good as I write, and I don't listen as good as I speak.

2018-02-04 11:24:03 (edited by stefan_ilioaica 2018-02-04 11:24:31)

Hi,
I've found a quite decent solution for my issue, I guess. But, I still have one more question: is it possible to create bidimensional sound  arrais in bgt, then to play that sound?
I have 11 characters, each one with their three skills.
And also, can you explain me a bit about polymorphism?

2018-02-04 12:10:47

It's true that you can Access the string from everywhere but I thought it would be good to explain getter methods since they are often used in larger Projects, especially for Commercial Projects. It was just a Little example how they work. But yes, it is a global variable and so you don't really Need a function for it.

We are pleased, that you made it through the final challenge, where we pretended we were going to murder you. We are throwing a party in honor of your tremendous success. Place the device on the ground, then lay on your stomach with your arms at your sides. A party associate will arrive shortly to collect you for your party. Assume the party submission position or you will miss the party.

2018-02-05 05:46:01

Yeah.Ideally it should be encapsulated into a static object or whatever, but lots of people seem to find it difficult to utilize classes.

I don't speak as good as I write, and I don't listen as good as I speak.