Help with what should be a very simple code task.

Thread Solved
Reply

Join Date: Jan 2009
Posts: 8
Reputation: Grimshad is an unknown quantity at this point 
Solved Threads: 0
Grimshad Grimshad is offline Offline
Newbie Poster

Help with what should be a very simple code task.

 
0
  #1
Jan 3rd, 2009
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
  1. var config bool ToggleWarhead;
and later put
  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
  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
  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?:
  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,149
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1435
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

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

 
0
  #2
Jan 3rd, 2009
If you want any responoses you need to state the compiler and operating system you are working with.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,838
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 266
ddanbe's Avatar
ddanbe ddanbe is online now Online
Posting Virtuoso

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

 
0
  #3
Jan 3rd, 2009
It seems weird to me that a method called AddSettings would create a global variable you declared earlier.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 117
Reputation: u8sand is on a distinguished road 
Solved Threads: 15
u8sand's Avatar
u8sand u8sand is offline Offline
Junior Poster

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

 
1
  #4
Jan 3rd, 2009
dono what this does really but who knows its worth a try

  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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 8
Reputation: Grimshad is an unknown quantity at this point 
Solved Threads: 0
Grimshad Grimshad is offline Offline
Newbie Poster

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

 
0
  #5
Jan 3rd, 2009
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

  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
  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
  1. var bool ToggleWarhead;
and i get
  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 482
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 47
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

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

 
0
  #6
Jan 3rd, 2009
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
¿umop apisdn upside down?
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 8
Reputation: Grimshad is an unknown quantity at this point 
Solved Threads: 0
Grimshad Grimshad is offline Offline
Newbie Poster

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

 
0
  #7
Jan 3rd, 2009
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:

  1. Begin Object Class=Class Name=TFGame
  2. End Object

and

  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
Last edited by Grimshad; Jan 3rd, 2009 at 6:38 pm.
Attached Files
File Type: zip TFCode.zip (19.6 KB, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 8
Reputation: Grimshad is an unknown quantity at this point 
Solved Threads: 0
Grimshad Grimshad is offline Offline
Newbie Poster

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

 
0
  #8
Jan 3rd, 2009
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"
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

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

 
0
  #9
Jan 3rd, 2009
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;
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 8
Reputation: Grimshad is an unknown quantity at this point 
Solved Threads: 0
Grimshad Grimshad is offline Offline
Newbie Poster

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

 
0
  #10
Jan 3rd, 2009
I changed it to
  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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC