Nerd-Rage Modders
Nerd-Rage Modders
Nerd-Rage Modders
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Nerd-Rage Modders

Nerd-Rage Modders
 
HomeHomeSearchLatest imagesRegisterLog in

 

 Using the Function: Createdvar

Go down 
AuthorMessage
Waffles




Posts : 12
Points : 46
Join date : 2010-03-05

Using the Function: Createdvar Empty
PostSubject: Using the Function: Createdvar   Using the Function: Createdvar EmptySat Mar 13, 2010 9:15 pm

To use this function, this code needs to be present within the file or from an include:

Code:

createdvar(varname, vardefault, min, max, type)
{
   if(type == "int")
   {
      if(getdvar(varname) == "")
         definition = vardefault;
      else
         definition = getdvarint(varname);
   }
   else if(type == "float")
   {
      if(getdvar(varname) == "")
         definition = vardefault;
      else
         definition = getdvarfloat(varname);
   }
   else
   {
      if(getdvar(varname) == "")
         definition = vardefault;
      else
         definition = getdvar(varname);
   }

   if((type == "int" || type == "float") && min != 0 && definition < min)
      definition = min;

   if((type == "int" || type == "float") && max != 0 && definition > max)
      definition = max;

   if(getdvar( varname ) == "")
      setdvar( varname, definition );

   return definition;
}

To use it to create string dvars:
Code:

createdvar( <dvar>, <default value>, <empty>, <empty>, <type> )

e.g.

createdvar( "scr_show", "hey", "", "", "string" );

To use it to create float dvars:
Code:

createdvar( <dvar>, <default value>, <minimum value>, <maximum value>, <type> )

e.g.

createdvar( "scr_speedtime", 1.32, 1.2, 1.4, "float" );

To use it to create int dvars:
Code:

createdvar( <dvar>, <default value>, <minimum value>, <maximum value>, <type> )

e.g.

createdvar( "scr_speedwait", 2, 1, 4, "int" );

This function is very useful for quickly making dvars and ensuring they have the correctly default values, rather than using annoying rows of if statements.
Back to top Go down
 
Using the Function: Createdvar
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Nerd-Rage Modders :: User Tutorial's :: Modding Tutorial's-
Jump to: