0

I am trying to build a program that allows for the simplification of the stage selection procedures in Smash. The main Way I am trying to allow the user to ban stages is to set a series of Boolean functions that they set as true or false so that illegal stages will never show up. The problem is, the Boolean variables I have in the function will not change from true to false.

the "Aban1" function is just supposed to take in the first ban, and make the variable associated with that stage as false. (this is not working and the source of the problem)

The "stagespitter function compares the boolean variables to another set that has already been set up by the user. it only outputs the stages if both the preset stage is true, and the stage that is able to be banned is true.

I have tried enumerated data types, although I think that was the wrong way to attempt this, as visual studio says that enums aren't modifiable variables.

void Aban1(string ban1, bool PS2, bool PS1, bool BF, bool FD, bool SMASHVILLE, bool KALOS, bool TOWN, bool LYLAT, bool STORY, bool ISLAND);

void stagespitter(bool LYLAT, char chLylat, bool chPS1, bool PS1, bool PS2, char chPS2, char chBF, bool BF, char chFD, bool FD, char chIsland, bool ISLAND, char chStory, bool STORY, char chTown, bool TOWN, char chKalos, bool KALOS, char chSmashville, bool SMASHVILLE); //spits out the stages that are available


void Aban1(string ban1, bool PS2, bool PS1, bool BF, bool FD, bool SMASHVILLE, bool KALOS, bool TOWN, bool LYLAT, bool STORY, bool ISLAND) { //this should run the s
if (ban1 == "PS2" || ban1 == "ps2" ) { 
    PS2 = false;
    cout << "Banned ps2" << endl;
}
else if (ban1 == "PS1" || ban1 == "ps1") {
    PS1 = false;
}
else if (ban1 == "BF" || ban1 == "bf" || ban1 == "bF") {
    BF = false;
}
else if (ban1 == "Smash" || ban1 == "smash") {   //remember to set direction for this, as you have to type specifically
    SMASHVILLE = false;
}
else if (ban1 == "Kalos" || ban1 == "kalos") {
    KALOS = false;
}
else if (ban1 == "Town" || ban1 == "town") {
    TOWN = false;
}
else if (ban1 == "FD" || ban1 == "fd" || ban1 == "fd") {
    FD = false;
}
else if (ban1 == "story" || ban1 == "Story") {
    STORY = false;
}
else if (ban1 == "Lylat" || ban1 == "lylat") {
    LYLAT = false;
} //make the final else loop it back
else (ban1 == "Island" || ban1 == "island"); { //instead of running this over and over, make a function that compares the state of true and false of the bools and the functions associated with the stage
    ISLAND = false; //and compares them only returning if both they accepted a stage, and it aint false, or not banned yet
}}


void stagespitter(bool LYLAT, char chLylat, bool chPS1, bool PS1, bool PS2, char chPS2, char chBF, bool BF, char chFD, bool FD, char chIsland, bool ISLAND, char chStory, bool STORY, char chTown, bool TOWN, char chKalos, bool KALOS, char chSmashville, bool SMASHVILLE) {
cout << "the Available stages are" << endl;

if (lylat(chLylat) == LYLAT && LYLAT == true) //set the bools equal to the function
    cout << "Lylat Cruise" << endl;

if ((ps1(chPS1) == PS1) && (PS1 == true))
    cout << "Pokemon Stadium 1" << endl;

if ((ps2(chPS2) == PS2) && (PS2 == true))
    cout << "Pokemon Stadium 2" << endl;

if (battlefield(chBF) == BF && BF == true)
    cout << "Battlefield" << endl;

if (finalDestination(chFD) == FD && FD == true) //something wrong here not adding up
    cout << "Final Destination" << endl;

//not correctly orienting what is false, and giving stages that have already been delcared not valid
if (yoshisIsland(chIsland) == ISLAND && ISLAND == true)//check the set equal parameters
    cout << "YoShi's Island" << endl;

if (yoshisStory(chStory) == STORY && STORY == true)
    cout << "Yoshi's Story" << endl;

if (townAndCity(chTown) == TOWN && TOWN == true)
    cout << "Town and City" << endl;

if (kalos(chKalos) == KALOS && KALOS == true)
    cout << "Kalos" << endl;

if (smashville(chSmashville) == SMASHVILLE && SMASHVILLE == true)
    cout << "Smashville" << endl;}

I want the boolean variables to be able to be set as false, right now they are not being set as false. I will also later need to reset the variables to true, but I am not at that point yet.

Lanai
  • 1
  • 3
    I'm certain that you can make a smaller and more-complete example out of this that will allow us to make a concrete answer, but I think you are after [What's the difference between passing by reference vs. passing by value?](https://stackoverflow.com/questions/373419/whats-the-difference-between-passing-by-reference-vs-passing-by-value) – user4581301 Apr 20 '19 at 03:24

1 Answers1

0

I am going to assume that you are calling ABan1() then stageSplitter() somewhere one after the other. In C++ when you call function, the parameters make all new copies of themselves, then when the function ends, they all disappear. This is called call by value. The booleans will be set in the function, but once the function ends they will not be set anymore. To fix this you can use a call be reference by putting a & before all of your parameters. This will change the original values that you used as parameters in your function. Here is a link that may help explain it a bit better: https://www.javatpoint.com/call-by-value-and-call-by-reference-in-cpp Hope this helps!!

Nick M
  • 1
  • Thanks for the tip, that was something I never learned in class, however, now that I have added that I get an error saying unresolved external symbol. – Lanai Apr 20 '19 at 16:22