943,843 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 909
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jan 3rd, 2009
0

Help with what should be a very simple code task.

Expand Post »
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
C++ Syntax (Toggle Plain Text)
  1. var config bool ToggleWarhead;
and later put
C++ Syntax (Toggle Plain Text)
  1. 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
C++ Syntax (Toggle Plain Text)
  1. case SMS_Construction:
  2. SMNameArray[0] = "Shield (50/30)";
  3. SMIndexArray[0] = 1;
  4. SMNameArray[1] = "Protector (200/30)";
  5. SMIndexArray[1] = 2;
  6. SMNameArray[2] = "Portal (200/30)";
  7. SMIndexArray[2] = 3;
  8. SMNameArray[3] = "Armory (200/60)";
  9. SMIndexArray[3] = 4;
  10. SMNameArray[4] = "Generator (300/60)";
  11. SMIndexArray[4] = 5;
  12. SMNameArray[5] = "Outpost (600/90)";
  13. SMIndexArray[5] = 6;
  14. if(tfgame.ToggleWarhead == True)
  15. {
  16. SMNameArray[6] = "Warhead (3000/180)";
  17. SMIndexArray[6] = 7;
  18. }
  19. SMArraySize=7;
  20. 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
C++ Syntax (Toggle Plain Text)
  1. "Error, Bad or Missing Expression in 'if'
  2.  

So I have 2 questions
1. Should my code for the if statement on the array include the difference in array size like so?:
C++ Syntax (Toggle Plain Text)
  1. case SMS_Construction:
  2. SMNameArray[0] = "Shield (50/30)";
  3. SMIndexArray[0] = 1;
  4. SMNameArray[1] = "Protector (200/30)";
  5. SMIndexArray[1] = 2;
  6. SMNameArray[2] = "Portal (200/30)";
  7. SMIndexArray[2] = 3;
  8. SMNameArray[3] = "Armory (200/60)";
  9. SMIndexArray[3] = 4;
  10. SMNameArray[4] = "Generator (300/60)";
  11. SMIndexArray[4] = 5;
  12. SMNameArray[5] = "Outpost (600/90)";
  13. SMIndexArray[5] = 6;
  14. if(tfgame.ToggleWarhead == True)
  15. {
  16. SMNameArray[6] = "Warhead (3000/180)";
  17. SMIndexArray[6] = 7;
  18. SMArraySize=7;
  19. }
  20. SMArraySize=6;
  21. 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Grimshad is offline Offline
8 posts
since Jan 2009
Jan 3rd, 2009
0

Re: Help with what should be a very simple code task.

If you want any responoses you need to state the compiler and operating system you are working with.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,951 posts
since Aug 2005
Jan 3rd, 2009
0

Re: Help with what should be a very simple code task.

It seems weird to me that a method called AddSettings would create a global variable you declared earlier.
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is online now Online
3,738 posts
since Oct 2008
Jan 3rd, 2009
1

Re: Help with what should be a very simple code task.

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

C++ Syntax (Toggle Plain Text)
  1. if(tfgame.ToggleWarhead == True)
  2. {
  3. SMNameArray[6] = "Warhead (3000/180)";
  4. SMIndexArray[6] = 7;
  5. SMArraySize=7;
  6. }

maybe replace True with true?

just to be safe just make it:
C++ Syntax (Toggle Plain Text)
  1. if(tfgame.ToggleWarhead)
  2. {
  3. SMNameArray[6] = "Warhead (3000/180)";
  4. SMIndexArray[6] = 7;
  5. SMArraySize=7;
  6. }
maybe that works?
Last edited by u8sand; Jan 3rd, 2009 at 10:36 am.
Reputation Points: 78
Solved Threads: 15
Junior Poster
u8sand is offline Offline
131 posts
since Dec 2008
Jan 3rd, 2009
0

Re: Help with what should be a very simple code task.

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

C++ Syntax (Toggle Plain Text)
  1. if(tfgame.ToggleWarhead == true)
  2. {
  3. case SMS_Construction:
  4. SMNameArray[0] = "Shield (50/30)";
  5. SMIndexArray[0] = 1;
  6. SMNameArray[1] = "Protector (200/30)";
  7. SMIndexArray[1] = 2;
  8. SMNameArray[2] = "Portal (200/30)";
  9. SMIndexArray[2] = 3;
  10. SMNameArray[3] = "Armory (200/60)";
  11. SMIndexArray[3] = 4;
  12. SMNameArray[4] = "Generator (300/60)";
  13. SMIndexArray[4] = 5;
  14. SMNameArray[5] = "Outpost (600/90)";
  15. SMIndexArray[5] = 6;
  16. SMArraySize=6;
  17. else
  18. case SMS_Construction:
  19. SMNameArray[0] = "Shield (50/30)";
  20. SMIndexArray[0] = 1;
  21. SMNameArray[1] = "Protector (200/30)";
  22. SMIndexArray[1] = 2;
  23. SMNameArray[2] = "Portal (200/30)";
  24. SMIndexArray[2] = 3;
  25. SMNameArray[3] = "Armory (200/60)";
  26. SMIndexArray[3] = 4;
  27. SMNameArray[4] = "Generator (300/60)";
  28. SMIndexArray[4] = 5;
  29. SMNameArray[5] = "Outpost (600/90)";
  30. SMIndexArray[5] = 6;
  31. SMNameArray[6] = "Warhead (3000/180)";
  32. SMIndexArray[6] = 7;
  33. SMArraySize=7;
  34. }

I added
C++ Syntax (Toggle Plain Text)
  1. 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
[/CODE]Error, Type mismatch in 'if'[/CODE]
Just found out that Bool meant True or False so I changed it to
C++ Syntax (Toggle Plain Text)
  1. var bool ToggleWarhead;
and i get
C++ Syntax (Toggle Plain Text)
  1. 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
Last edited by Grimshad; Jan 3rd, 2009 at 6:21 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Grimshad is offline Offline
8 posts
since Jan 2009
Jan 3rd, 2009
0

Re: Help with what should be a very simple code task.

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
Reputation Points: 307
Solved Threads: 62
Posting Pro
Bench is offline Offline
565 posts
since Feb 2006
Jan 3rd, 2009
0

Re: Help with what should be a very simple code task.

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:

C++ Syntax (Toggle Plain Text)
  1. Begin Object Class=Class Name=TFGame
  2. End Object

and

C++ Syntax (Toggle Plain Text)
  1. Begin Object Class=BoolProperty Name=ToggleWarhead
  2. End Object
I don't think this has anything to do with my problem though.

I appreciate the help Bench
Attached Files
File Type: zip TFCode.zip (19.6 KB, 23 views)
Last edited by Grimshad; Jan 3rd, 2009 at 6:38 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Grimshad is offline Offline
8 posts
since Jan 2009
Jan 3rd, 2009
0

Re: Help with what should be a very simple code task.

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"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Grimshad is offline Offline
8 posts
since Jan 2009
Jan 3rd, 2009
0

Re: Help with what should be a very simple code task.

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;
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jan 3rd, 2009
0

Re: Help with what should be a very simple code task.

I changed it to
C++ Syntax (Toggle Plain Text)
  1. if(TFGame.ToggleWarhead == true)
  2. {
  3. case SMS_Construction:
  4. SMNameArray[0] = "Shield (50/30)";
  5. SMIndexArray[0] = 1;
  6. SMNameArray[1] = "Protector (200/30)";
  7. SMIndexArray[1] = 2;
  8. SMNameArray[2] = "Portal (200/30)";
  9. SMIndexArray[2] = 3;
  10. SMNameArray[3] = "Armory (200/60)";
  11. SMIndexArray[3] = 4;
  12. SMNameArray[4] = "Generator (300/60)";
  13. SMIndexArray[4] = 5;
  14. SMNameArray[5] = "Outpost (600/90)";
  15. SMIndexArray[5] = 6;
  16. SMArraySize=6;
  17. else
  18. case SMS_Construction:
  19. SMNameArray[0] = "Shield (50/30)";
  20. SMIndexArray[0] = 1;
  21. SMNameArray[1] = "Protector (200/30)";
  22. SMIndexArray[1] = 2;
  23. SMNameArray[2] = "Portal (200/30)";
  24. SMIndexArray[2] = 3;
  25. SMNameArray[3] = "Armory (200/60)";
  26. SMIndexArray[3] = 4;
  27. SMNameArray[4] = "Generator (300/60)";
  28. SMIndexArray[4] = 5;
  29. SMNameArray[5] = "Outpost (600/90)";
  30. SMIndexArray[5] = 6;
  31. SMNameArray[6] = "Warhead (3000/180)";
  32. SMIndexArray[6] = 7;
  33. SMArraySize=7;
  34. }

Still gives me the same error, Bad or Missing Expression in 'if'
Last edited by Grimshad; Jan 3rd, 2009 at 10:07 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Grimshad is offline Offline
8 posts
since Jan 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: XP Window Hide
Next Thread in C++ Forum Timeline: How do I create a program that creates a file that stores the variables data?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC