Thread: Custom CVar system

  1. #16
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    	if(head == 0)
    	{
    		head->name = name;
    		head->value = value;
    		head->locked = lock;
    		return;
    	}
    Code:
    	if(head == 0)
    	{
    		head = new rCVar;
    		head->name = name;
    		head->value = value;
    		head->locked = lock;
    		return;
    	}
    You could make a constructor for your struct/class to make it easier;

    Code:
    	if(head == 0)
    	{
    		head = new rCVar(name, value, lock);
    		return;
    	}

  2. #17
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    Ok I updated it, after thinking it over last night. Found a few extra stuff that wasn't needed.

    Code:
    //setNew: Sets a new cvar if an existing one of the same
    // 		  name doesn't exist.
    void rCVarEngine::set(const char *name, const char *value,bool lock)
    {
    	// If we don't have a cvar in our head
    	// then set it
    	if(head == 0)
    	{
    		head = new rCVar(name,value,lock);
    		return;
    		
    	}
    	// If our current cvarList value hasn't been set
    	// then set it...yo
    	else if(cvarList == 0)
    	{
    		cvarList = new rCVar(name,value,lock);
    		head->next = cvarList;
    		return;
    	}
    
    	while(cvarList)
    	{
    		// If we found an existing CVar
    		// then set its value and lock
    		// mode
    		if(strcmp(cvarList->name, name))
    		{
    			cvarList->value = value;
    			cvarList->locked = lock;
    			return;
    
    		}
    		// Else if the next in the list is empty
    		// Set its new values
    		else if(cvarList->next == 0) 
    		{
    
    					
    			// Add it to the end
    			cvarList->next = new rCVar(name,value,lock);
                            return;
    		} 
    		// If we havn't found the end of the
    		// list or if we havn't found a pre-
    		// existing cvar, then move to the 
    		// next in the list
    		else 
    		{
    				
    			cvarList = cvarList->next;
    		} 
    		
    	}
    	
    }
    But it still crashes.


    Code:
    struct rCVar
    {	
    
    	const char *name;
    	const char *value;
    	bool locked;
    	rCVar *next;
    	
    	// Constructor
    	rCVar(const char *cName, const char *cValue, bool cLock)
    	{
    		name = cName;
    		value = cValue;
    		locked = cLock;
    		next = 0;
    	}
    
    };
    Your mom is like a struct, she has no class

    How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Press a key
    By siavoshkc in forum C++ Programming
    Replies: 30
    Last Post: 01-21-2006, 10:15 AM
  2. New system build wont boot
    By lightatdawn in forum Tech Board
    Replies: 7
    Last Post: 12-02-2005, 06:58 AM
  3. Using mscorlib & system namespace in an MFC?
    By Robert_Sitter in forum C++ Programming
    Replies: 3
    Last Post: 11-13-2005, 06:47 PM
  4. Opinions on custom system build
    By lightatdawn in forum Tech Board
    Replies: 2
    Last Post: 10-18-2005, 04:15 AM
  5. system();
    By GanglyLamb in forum C Programming
    Replies: 5
    Last Post: 10-30-2002, 03:57 AM