Skip to main content

I’m coding a text-based RPG and I have my controls working: I have a string checking what you write in against an array of if statements.

It can get it right with everything other than my pick up action.

My if statements are set out as follows:

int game_main() { 

    string PlayerOption;

    //I have a few lines of cout statements just for my gui/hud

    cin >> PlayerOption;

    if (PlayerOption == “look”"look") { 
        //it’s then just calling a script from a separate header file 
    }
    else if (PlayerOption == “pick"pick up”up") {
        //another script from that header 
    }

My look command and all my others work but I don’t know how to set it up right.

I've tried putting it like “pick up”"pick up", I tried it like “pick”” “”up”"pick"" ""up" and a couple other ways but I don’t know how to properly write the expression.

Even then my problem might be with my string and not my if statement so any suggestions would be greatly appreciated.

And I think @DMGregory might be right about the word boundaries because even with that command if I make it accept "pick" it works it’s only when I ask it for two words it really breaks

Is there any way I could get around that?

I’m coding a text-based RPG and I have my controls working: I have a string checking what you write in against an array of if statements.

It can get it right with everything other than my pick up action.

My if statements are set out as follows:

int game_main() { 

    string PlayerOption;

    //I have a few lines of cout statements just for my gui/hud

    cin >> PlayerOption;

    if (PlayerOption == “look”) { 
        //it’s then just calling a script from a separate header file 
    }
    else if (PlayerOption == “pick up”) {
        //another script from that header 
    }

My look command and all my others work but I don’t know how to set it up right.

I've tried putting it like “pick up”, I tried it like “pick”” “”up” and a couple other ways but I don’t know how to properly write the expression.

Even then my problem might be with my string and not my if statement so any suggestions would be greatly appreciated.

And I think @DMGregory might be right about the word boundaries because even with that command if I make it accept "pick" it works it’s only when I ask it for two words it really breaks

Is there any way I could get around that?

I’m coding a text-based RPG and I have my controls working: I have a string checking what you write in against an array of if statements.

It can get it right with everything other than my pick up action.

My if statements are set out as follows:

int game_main() { 

    string PlayerOption;

    //I have a few lines of cout statements just for my gui/hud

    cin >> PlayerOption;

    if (PlayerOption == "look") { 
        //it’s then just calling a script from a separate header file 
    }
    else if (PlayerOption == "pick up") {
        //another script from that header 
    }

My look command and all my others work but I don’t know how to set it up right.

I've tried putting it like "pick up", I tried it like "pick"" ""up" and a couple other ways but I don’t know how to properly write the expression.

Even then my problem might be with my string and not my if statement so any suggestions would be greatly appreciated.

And I think @DMGregory might be right about the word boundaries because even with that command if I make it accept "pick" it works it’s only when I ask it for two words it really breaks

Is there any way I could get around that?

Typo
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

I’m coding a text-based RPG and I have my controls working: I have a string checking what you write in against an array of if statements.

It can get it right with everything other than my pick up action.

My if statements are set out as follows:

int game_main() { 

    string PlayerOption;

    //I have a few lines of cout statements just for my gui/hud

    cin >> PlayerOption;

    if (PlayerOption == “look”) { 
        //it’s then just calling a script from a separate header file 
    }
    else if (PlayerOption == “pick up”) {
        //another script from that header 
    }

My look command and all my others work but I don’t know how to set it up right.

I've tried putting it like “pick up”, I tried it like “pick”” “”up” and a couple other ways but I don’t know how to properly write the expression.

Even then my problem might be with my string and not my if statement so any suggestions would be greatly appreciated.

And I think @DMGregort@DMGregory might be right about the word boundaries because even with that command if I make it accept "pick" it works it’s only when I ask it for two words it really breaks

Is there any way I could get around that?

I’m coding a text-based RPG and I have my controls working: I have a string checking what you write in against an array of if statements.

It can get it right with everything other than my pick up action.

My if statements are set out as follows:

int game_main() { 

    string PlayerOption;

    //I have a few lines of cout statements just for my gui/hud

    cin >> PlayerOption;

    if (PlayerOption == “look”) { 
        //it’s then just calling a script from a separate header file 
    }
    else if (PlayerOption == “pick up”) {
        //another script from that header 
    }

My look command and all my others work but I don’t know how to set it up right.

I've tried putting it like “pick up”, I tried it like “pick”” “”up” and a couple other ways but I don’t know how to properly write the expression.

Even then my problem might be with my string and not my if statement so any suggestions would be greatly appreciated.

And I think @DMGregort might be right about the word boundaries because even with that command if I make it accept "pick" it works it’s only when I ask it for two words it really breaks

Is there any way I could get around that?

I’m coding a text-based RPG and I have my controls working: I have a string checking what you write in against an array of if statements.

It can get it right with everything other than my pick up action.

My if statements are set out as follows:

int game_main() { 

    string PlayerOption;

    //I have a few lines of cout statements just for my gui/hud

    cin >> PlayerOption;

    if (PlayerOption == “look”) { 
        //it’s then just calling a script from a separate header file 
    }
    else if (PlayerOption == “pick up”) {
        //another script from that header 
    }

My look command and all my others work but I don’t know how to set it up right.

I've tried putting it like “pick up”, I tried it like “pick”” “”up” and a couple other ways but I don’t know how to properly write the expression.

Even then my problem might be with my string and not my if statement so any suggestions would be greatly appreciated.

And I think @DMGregory might be right about the word boundaries because even with that command if I make it accept "pick" it works it’s only when I ask it for two words it really breaks

Is there any way I could get around that?

Putting edit inside question itself
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

I’m coding a text-based RPG and I have my controls working: I have a string checking what you write in against an array of if statements.

It can get it right with everything other than my pick up action.

My if statement isstatements are set out as follows:

ifint game_main(PlayerOption) { 

    string PlayerOption;

    //That’sI thehave Stringa few lines of cout statements just for my gui/hud

    cin >> PlayerOption;

    if (PlayerOption == “look”) { 
        //it’s then just calling a script from a separate header file 
    }
    else if (PlayerOption == “blah”“pick up”) {
        //another script from that header 
    }

and that works with one word commands but it breaks when it comes to the two word command of pick up. How can I can compare the string against two words?

//edit 1

int game_main() { string PlayerOption;

//I have a few lines of cout statements just for my gui/hud

cin >> PlayerOption;

If (PlayerOption == “look”)

{ //it’s then just calling a script from a separate header file }

Else if (PlayerOption == “pick up”)

{ //another script from that header }

My look command and all my others work but I don’t know how to set it up right iv.

I've tried putting it like “pick up”  , I tried it like “pick”” “”up” and a couple other ways but I don’t know how to properly write the expression and even.

Even then my problem might be with my string and not my if statement so any suggestions would be greatly appreciated

Edit//.

And I think you@DMGregort might be right about the word boundaries because even with that command if I make it accept pick"pick" it works it’s only when I ask it for two words and actually use the whole term of “pick up” it really breaks is

Is there anywayany way I could get around that and I could just use pick or pickup but I feel like that’s just backing away from what is probably a really easy issue to sort?

I’m coding a text-based RPG and I have my controls working: I have a string checking what you write in against an array of if statements.

It can get it right with everything other than my pick up action.

My if statement is set out as follows:

if (PlayerOption //That’s the String// == “blah”) 

and that works with one word commands but it breaks when it comes to the two word command of pick up. How can I can compare the string against two words?

//edit 1

int game_main() { string PlayerOption;

//I have a few lines of cout statements just for my gui/hud

cin >> PlayerOption;

If (PlayerOption == “look”)

{ //it’s then just calling a script from a separate header file }

Else if (PlayerOption == “pick up”)

{ //another script from that header }

My look command and all my others work but I don’t know how to set it up right iv tried putting it like “pick up”  , I tried it like “pick”” “”up” and a couple other ways but I don’t know how to properly write the expression and even then my problem might be with my string and not my if statement so any suggestions would be greatly appreciated

Edit//

And I think you might be right about the word boundaries because even with that command if I make it accept pick it works it’s only when I ask it for two words and actually use the whole term of “pick up” it really breaks is there anyway I could get around that and I could just use pick or pickup but I feel like that’s just backing away from what is probably a really easy issue to sort

I’m coding a text-based RPG and I have my controls working: I have a string checking what you write in against an array of if statements.

It can get it right with everything other than my pick up action.

My if statements are set out as follows:

int game_main() { 

    string PlayerOption;

    //I have a few lines of cout statements just for my gui/hud

    cin >> PlayerOption;

    if (PlayerOption == “look”) { 
        //it’s then just calling a script from a separate header file 
    }
    else if (PlayerOption == “pick up”) {
        //another script from that header 
    }

My look command and all my others work but I don’t know how to set it up right.

I've tried putting it like “pick up”, I tried it like “pick”” “”up” and a couple other ways but I don’t know how to properly write the expression.

Even then my problem might be with my string and not my if statement so any suggestions would be greatly appreciated.

And I think @DMGregort might be right about the word boundaries because even with that command if I make it accept "pick" it works it’s only when I ask it for two words it really breaks

Is there any way I could get around that?

added 1073 characters in body
Source Link
Loading
Cleanup
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401
Loading
Source Link
Loading