I'm looking for some help with some C++ code. I have working knowledge and understanding of code and coding in general, but don't actually program myself.

I have 2 files

TFGame

and

TFMenuConsole

In TFGame I put

var config bool ToggleWarhead;

and later put

PlayInfo.AddSetting(default.GameGroup, "ToggleWarhead",    default.SIGPropsDisplayText[i++], 0,  1, "Check",        ,,     , true);

To my knowledge, this will create the variable ToggleWarhead and then add a check box to the settings menu to toggle this variable true or false (default being true) and also display the string value that is set for SIGPropsDisplayText for the setting name.

In TFMenuConsole I put

case SMS_Construction:
			SMNameArray[0] = "Shield (50/30)";
			SMIndexArray[0] = 1;
            		SMNameArray[1] = "Protector (200/30)";
			SMIndexArray[1] = 2;
			SMNameArray[2] = "Portal (200/30)";
			SMIndexArray[2] = 3;
			SMNameArray[3] = "Armory (200/60)";
			SMIndexArray[3] = 4;
			SMNameArray[4] = "Generator (300/60)";
			SMIndexArray[4] = 5;
			SMNameArray[5] = "Outpost (600/90)";
			SMIndexArray[5] = 6;
	            if(tfgame.ToggleWarhead == True)
			        {
			            SMNameArray[6] = "Warhead (3000/180)";
			            SMIndexArray[6] = 7;
			        }
			SMArraySize=7;
			break;

Which should Check if the variable ToggleWarhead in the File TFGame is true, if it is then it will execute array number 6, if not then it should skip it and Warhead should be left out of the Array.

When I try to compile I get this

"Error, Bad or Missing Expression in 'if'

So I have 2 questions
1. Should my code for the if statement on the array include the difference in array size like so?:

case SMS_Construction:
			SMNameArray[0] = "Shield (50/30)";
			SMIndexArray[0] = 1;
            		SMNameArray[1] = "Protector (200/30)";
			SMIndexArray[1] = 2;
			SMNameArray[2] = "Portal (200/30)";
			SMIndexArray[2] = 3;
			SMNameArray[3] = "Armory (200/60)";
			SMIndexArray[3] = 4;
			SMNameArray[4] = "Generator (300/60)";
			SMIndexArray[4] = 5;
			SMNameArray[5] = "Outpost (600/90)";
			SMIndexArray[5] = 6;
	            if(tfgame.ToggleWarhead == True)
			        {
			            SMNameArray[6] = "Warhead (3000/180)";
			            SMIndexArray[6] = 7;
                                    SMArraySize=7;
			        }
			SMArraySize=6;
			break;

and 2. What am I doing wrong? why is it not working?

I'm sure it is because of the format I put the if statement in, I am not used to C++ and I only understand code, I don't actually know how to code.

Any help would be greatly appreciated.
I can also provide the source files if your willing to help me solve this.

Thanks,
Grim

Recommended Answers

All 15 Replies

If you want any responoses you need to state the compiler and operating system you are working with.

It seems weird to me that a method called AddSettings would create a global variable you declared earlier.

dono what this does really but who knows its worth a try

if(tfgame.ToggleWarhead == True)
			        {
			            SMNameArray[6] = "Warhead (3000/180)";
			            SMIndexArray[6] = 7;
                                    SMArraySize=7;
			        }

maybe replace True with true?

just to be safe just make it:

if(tfgame.ToggleWarhead)
			        {
			            SMNameArray[6] = "Warhead (3000/180)";
			            SMIndexArray[6] = 7;
                                    SMArraySize=7;
			        }

maybe that works?

commented: Nice! True is not always true. +3

Thanks for the responses.

OS: V Extreme
Compiler: UCC

I tried running with the True uncapitalized

Same Error

I tried with the new array size in the if statement

Same Error

I tried without the == true

Same Error

I also tried putting the whole array into the if

    if(tfgame.ToggleWarhead == true)
           {
     case SMS_Construction:
        SMNameArray[0] = "Shield (50/30)";
        SMIndexArray[0] = 1;
                SMNameArray[1] = "Protector (200/30)";
        SMIndexArray[1] = 2;
        SMNameArray[2] = "Portal (200/30)";
        SMIndexArray[2] = 3;
        SMNameArray[3] = "Armory (200/60)";
        SMIndexArray[3] = 4;
        SMNameArray[4] = "Generator (300/60)";
        SMIndexArray[4] = 5;
        SMNameArray[5] = "Outpost (600/90)";
        SMIndexArray[5] = 6;
        SMArraySize=6;
    else
     case SMS_Construction:
        SMNameArray[0] = "Shield (50/30)";
        SMIndexArray[0] = 1;
                SMNameArray[1] = "Protector (200/30)";
        SMIndexArray[1] = 2;
        SMNameArray[2] = "Portal (200/30)";
        SMIndexArray[2] = 3;
        SMNameArray[3] = "Armory (200/60)";
        SMIndexArray[3] = 4;
        SMNameArray[4] = "Generator (300/60)";
        SMIndexArray[4] = 5;
        SMNameArray[5] = "Outpost (600/90)";
        SMIndexArray[5] = 6;
        SMNameArray[6] = "Warhead (3000/180)";
        SMIndexArray[6] = 7;
        SMArraySize=7;
         }

I added

var string ToggleWarhead;

to the beginning of the TFMenuConsole file to test if the error is when the variable is being called from the other file and when I tried to compile it returned

Error, Type mismatch in 'if'

Just found out that Bool meant True or False so I changed it to

var bool ToggleWarhead;

and i get

Error, class is not allowed here

It has to be the code itself, if someone could just lo ok at it for me and tell me what im doing wrong

In the latest code you posted, you're using the case keyword after an if statement. case is intended to be used in conjunction with switch, and is meaningless on its own.

Perhaps you could also show the declaration of your tfgame object, and the declaration for ToggleWarhead

I've attached the 2 files

In TFGame the Variable ToggleWarhead is added on line 15

In TFMenuConsole the variable needs to be used on line 1068

In TFGame the variable is created and used in Pre game settings menu where a check box toggles it true/false

In TFMenuConsole the If statement I am trying to impliment will remove the Warhead entry from the in game menu if ToggleWarhead is true, and will leave it there if it is false.

I noticed you said "tfgame object" I exported all objects from my file and there is a tfgame object and tfgame.ToggleWarhead object, they say:

Begin Object Class=Class Name=TFGame
End Object

and

Begin Object Class=BoolProperty Name=ToggleWarhead
End Object

I don't think this has anything to do with my problem though.

I appreciate the help Bench

This was quoted by someone who knows C++

"you are trying to use a class without firstly implementig it's creation, or loading it from somewhere"

but to my knowledge its creation is in the file TFGame

he also said

"you can't just put filename.variable and expect the compiler to know what your talking about"

Sure, but your if statement is looking for if(tfgame.ToggleWarhead == True) which from what I can tell is not the name of your class. Unless I've been living in *nix too long, and case doesn't matter any more: class TFGame extends xTeamGame;

I changed it to

if(TFGame.ToggleWarhead == true)
               {
		 case SMS_Construction:
			SMNameArray[0] = "Shield (50/30)";
			SMIndexArray[0] = 1;
            		SMNameArray[1] = "Protector (200/30)";
			SMIndexArray[1] = 2;
			SMNameArray[2] = "Portal (200/30)";
			SMIndexArray[2] = 3;
			SMNameArray[3] = "Armory (200/60)";
			SMIndexArray[3] = 4;
			SMNameArray[4] = "Generator (300/60)";
			SMIndexArray[4] = 5;
			SMNameArray[5] = "Outpost (600/90)";
			SMIndexArray[5] = 6;
			SMArraySize=6;
	    else
		 case SMS_Construction:
			SMNameArray[0] = "Shield (50/30)";
			SMIndexArray[0] = 1;
		        SMNameArray[1] = "Protector (200/30)";
			SMIndexArray[1] = 2;
			SMNameArray[2] = "Portal (200/30)";
			SMIndexArray[2] = 3;
			SMNameArray[3] = "Armory (200/60)";
			SMIndexArray[3] = 4;
			SMNameArray[4] = "Generator (300/60)";
			SMIndexArray[4] = 5;
			SMNameArray[5] = "Outpost (600/90)";
			SMIndexArray[5] = 6;
			SMNameArray[6] = "Warhead (3000/180)";
			SMIndexArray[6] = 7;
			SMArraySize=7;
             }

Still gives me the same error, Bad or Missing Expression in 'if'

The case statements are irrelevent -- they do absolutely nothing, so you should just delete them.

if(TFGame.ToggleWarhead == true)
               {
			SMNameArray[0] = "Shield (50/30)";
			SMIndexArray[0] = 1;
            		SMNameArray[1] = "Protector (200/30)";
			SMIndexArray[1] = 2;
			SMNameArray[2] = "Portal (200/30)";
			SMIndexArray[2] = 3;
			SMNameArray[3] = "Armory (200/60)";
			SMIndexArray[3] = 4;
			SMNameArray[4] = "Generator (300/60)";
			SMIndexArray[4] = 5;
			SMNameArray[5] = "Outpost (600/90)";
			SMIndexArray[5] = 6;
			SMArraySize=6;
           }
	    else
          {
			SMNameArray[0] = "Shield (50/30)";
			SMIndexArray[0] = 1;
		        SMNameArray[1] = "Protector (200/30)";
			SMIndexArray[1] = 2;
			SMNameArray[2] = "Portal (200/30)";
			SMIndexArray[2] = 3;
			SMNameArray[3] = "Armory (200/60)";
			SMIndexArray[3] = 4;
			SMNameArray[4] = "Generator (300/60)";
			SMIndexArray[4] = 5;
			SMNameArray[5] = "Outpost (600/90)";
			SMIndexArray[5] = 6;
			SMNameArray[6] = "Warhead (3000/180)";
			SMIndexArray[6] = 7;
			SMArraySize=7;
             }

AncientDragon, im sure theres a lot of sloppy code here.

But your comment didn't really help me get closer to my goal, of making the variable ToggleWarhead global so that i can use it in the file i need to use it in as an if statement

Thanks Though

The if and else need to be 'inside' the case, and the if block and else block need their own set of braces { }. if (test) { // code } else { // more code }

case SMS_Construction:
			if(tfgame.ToggleWarhead == true)
			{
				SMNameArray[0] = "Shield (50/30)";
				SMIndexArray[0] = 1;
				SMNameArray[1] = "Protector (200/30)";
				SMIndexArray[1] = 2;
				SMNameArray[2] = "Portal (200/30)";
				SMIndexArray[2] = 3;
				SMNameArray[3] = "Armory (200/60)";
				SMIndexArray[3] = 4;
				SMNameArray[4] = "Generator (300/60)";
				SMIndexArray[4] = 5;
				SMNameArray[5] = "Outpost (600/90)";
				SMIndexArray[5] = 6;
				SMArraySize=6;
			}
			else
			{
				SMNameArray[0] = "Shield (50/30)";
				SMIndexArray[0] = 1;
				SMNameArray[1] = "Protector (200/30)";
				SMIndexArray[1] = 2;
				SMNameArray[2] = "Portal (200/30)";
				SMIndexArray[2] = 3;
				SMNameArray[3] = "Armory (200/60)";
				SMIndexArray[3] = 4;
				SMNameArray[4] = "Generator (300/60)";
				SMIndexArray[4] = 5;
				SMNameArray[5] = "Outpost (600/90)";
				SMIndexArray[5] = 6;
				SMNameArray[6] = "Warhead (3000/180)";
				SMIndexArray[6] = 7;
				SMArraySize=7;
			}

But this should work too and be a lot smaller:

case SMS_Construction:
			SMNameArray[0] = "Shield (50/30)";
			SMIndexArray[0] = 1;
			SMNameArray[1] = "Protector (200/30)";
			SMIndexArray[1] = 2;
			SMNameArray[2] = "Portal (200/30)";
			SMIndexArray[2] = 3;
			SMNameArray[3] = "Armory (200/60)";
			SMIndexArray[3] = 4;
			SMNameArray[4] = "Generator (300/60)";
			SMIndexArray[4] = 5;
			SMNameArray[5] = "Outpost (600/90)";
			SMIndexArray[5] = 6;
			SMArraySize=6;
			if(tfgame.ToggleWarhead == true)
			{
				SMNameArray[6] = "Warhead (3000/180)";
				SMIndexArray[6] = 7;
				SMArraySize=7;
			}

PS- please use c++ language code tags when posting c++ source
[code=c++] // your code here

[/code]

After a little further searching, I don't see that any of the 'config' values from TFGame.uc (other than the one you are trying to add) are being used in TFMenuConsole anywhere.

Ok I found out some more info.

All of the other variables listed at the top of TFGame are in this format when being pulled by other files

if(tfgame(level.Game).variable == true)

When i use

if(tfgame(level.Game).ToggleWarhead == true)

the compiler returns

Error, Bad or Missing Expression in 'if'

If i add

local tfgame warhead

to the rest of the locals in TFMenuConsole

and then use

if(warhead.ToggleWarhead == true)

then the code compiles fine, but it doesn't actually do anything in the game. I'm assuming this is because the local object I just created is blank.

Ok, first ide like to thank everyone here
second, ide like to say im sorry because I didn't know what i was talking about

third, its fixed

if(class 'TFGame'.default.ToggleWarhead == True)

that worked, cuz there are no global variables in this script :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.