Please Help! Why can't I assign a value to these integers??

This is a discussion on Please Help! Why can't I assign a value to these integers?? within the C++ Programming forums, part of the General Programming Boards category; Hi all, I have programming for some time now PHP mainly and moved to C++ about six months ago for ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    2

    Please Help! Why can't I assign a value to these integers??

    Hi all,

    I have programming for some time now PHP mainly and moved to C++ about six months ago for game programming. I am currently at university in Coventry. The problem I am having is when attempting to assign a value of type int to another int. I know! its crazy as we do this all the time, so why wont my code work as it should??

    The code will be used in Ogre3D as part of a multiplayer lobby, but my problem is more C++ I think. It's not that a value isn't being assigned it is (sometimes 11, and sometimes 31) but certainly not what I expect which should be maximum 18 depending on what button was pressed 0-18. I can assure you that other than setting it to zero in the constructor, no other code alters the "lastClick" attribute, and there are no other classes using the same name (not as if that should matter). So why on earth wont the "lastClick" attribute accept the current value of the for loop. Where is it getting 11 or 31 from, is there some significance to these numbers?

    I have provided the header file "PlayerBoard.h" and the method where I am experiencing the problem in a hope that someone can advise me, its driving me crazy and I really have to move on. I have two assignments to do and an exam to revise for, poor me

    PlayerBoard.h
    Code:
    #pragma once
    #include "GuiWidget1.h"
    #include "GuiTrayListener1.h"
    #include <iostream>
    #include <string.h>
    static int MAXPLAYERS = 16;
    
    class PlayerBoard : public GuiWidget 
    {
    public:
    
    	int pressed[16];
    	///imageButton(const Ogre::String& name, const Ogre::DisplayString& caption, Ogre::Real width);
    
    	Ogre::StringVector mPlayersList;
    
    	void updatePlayers(Ogre::StringVector players);  //We need to pass in an string vector with connected players
    	
    	PlayerBoard(const Ogre::String& name);
    
    	////
    	int lastClick;
    	int lastClickB;
    	int lastOver;
    	int testerClicked;
    
    	Ogre::String mMaterialUsed;
    
    	OgreBites::ButtonState mState;
    	OgreBites::ButtonState mStateB;
    	Ogre::BorderPanelOverlayElement* mBP;
    	Ogre::BorderPanelOverlayElement* mBP2;
    	Ogre::BorderPanelOverlayElement* mBP3;
    	Ogre::BorderPanelOverlayElement* mBP4;
    	Ogre::BorderPanelOverlayElement* mBP5;
    	Ogre::BorderPanelOverlayElement* mBP6;
    	Ogre::BorderPanelOverlayElement* mBP7;
    	Ogre::BorderPanelOverlayElement* mBPs[20]; //first 16 are players next are used by logic for buttons
    	Ogre::TextAreaOverlayElement* mTextArea;
    	Ogre::TextAreaOverlayElement* mTextAreas[20];
    	Ogre::TextAreaOverlayElement* mTexts[16];
    	bool mFitToContents;
    
    	const Ogre::DisplayString& getCaption();
    	void setCaption(const Ogre::DisplayString& caption, int captionNum  );
    
    	const OgreBites::ButtonState& getState() { return mState; }
    	
    	void _cursorPressed(const Ogre::Vector2& cursorPos);
    	void _cursorReleased(const Ogre::Vector2& cursorPos);
    	void _cursorMoved(const Ogre::Vector2& cursorPos);
    	void _focusLost();
    
    	//
    	void setState(const OgreBites::ButtonState& bs, int bn); 
    
    	~PlayerBoard() {}
    };
    The method with the problem from "PlayerBoard.cpp":
    Code:
    void PlayerBoard::_cursorPressed(const Ogre::Vector2& cursorPos)
    {
    	for(int i=0; i<MAXPLAYERS+3; i++)
    	{	
    		if (isCursorOver(mBPs[i], cursorPos, 4)) 
    		{
    			if( i >= MAXPLAYERS)
    			{
    				// Set the last pressed button for this section back to UP
    				setState(OgreBites::BS_UP, lastClickB);
    				
    				for(int j = MAXPLAYERS; j < MAXPLAYERS+3; j++)
    				{
    					pressed[j] = 0;
    				}
    				setState(OgreBites::BS_DOWN, i);
    				lastClickB = i;
    
    				if (mListener) mListener->playerButtonHit(i);
    				switch(pressed[i]){
    				case 0: 
    					pressed[i] = 1;
    					break;
    				case 1:
    					pressed[i] = 0;
    					break;
    				}
    			}
    			else
    			{
    				// Set the last pressed button for this section back to UP
    				setState(OgreBites::BS_UP, lastClick);
    				
    				for(int j=0; j < MAXPLAYERS; j++)
    				{
    					pressed[j] = 0;
    				}
    
    				
    				setState(OgreBites::BS_DOWN, i);
    				lastClick = i;  ///Neither of these work????
    				testerClicked = i;   ///Neither of these work????				if (mListener) mListener->playerButtonHit(i);
    				switch(pressed[i]){
    				case 0: 
    					pressed[i] = 1;
    					break;
    				case 1:
    					pressed[i] = 0;
    					break;
    				}
    			}
    			
    			
    		}
    	}
    }
    The bit in red is the problem but if you look further up the same code (lastClickB = i; doesn't work either?

    I should probably mention that the "PlayerBoard" class inherits from another class "GuiWidget", which then inherits from another (Ogre3D) "SdkTrayMgr". The problematic method is assigned as "virtual" in the grandparent class and then I inherit to use when the cursor is over a button. All I want to do is remeber the button number and store it so I can change states after each click. If you need more code just say!

    Please go easy on me this is my first ever post anywhere on the web and I am still learning!
    Last edited by flawlesslee; 04-29-2011 at 02:07 PM. Reason: clarity

  2. #2
    Registered User
    Join Date
    Apr 2011
    Posts
    2
    [Solved] What a pain! Nothing to do with the int silly mistake that I must have gone blind to in another method!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. assign value to string
    By rahulsk1947 in forum C Programming
    Replies: 3
    Last Post: 04-06-2006, 03:40 AM
  2. Assign string to variable?
    By 98dodgeneondohc in forum C Programming
    Replies: 8
    Last Post: 04-24-2005, 01:51 PM
  3. can u assign structs to another
    By mackol in forum C Programming
    Replies: 2
    Last Post: 04-16-2003, 10:57 AM
  4. Is there a K.Assign Function?
    By Golffor1 in forum C++ Programming
    Replies: 1
    Last Post: 04-02-2003, 08:12 AM
  5. How to programmaticly assign two NICs the same IP
    By Fakhar in forum Windows Programming
    Replies: 0
    Last Post: 04-29-2002, 10:40 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21