Example #1
0
void setvariablevalue(svariable_t *v, svalue_t newvalue)
{
  if(killscript) return;  // protect the variables when killing script
  
  if(!v) return;
  
  if(v->type == svt_const)
    {
      // const adapts to the value it is set to
      v->type = newvalue.type;

      // alloc memory for string
      if(v->type == svt_string)   // static incase a global_script var
	v->value.s = Z_Malloc(128, PU_STATIC, 0);
    }
  
  if(v->type == svt_int)
    v->value.i = intvalue(newvalue);

  if(v->type == svt_string)
    strcpy(v->value.s, stringvalue(newvalue));

  if(v->type == svt_fixed)
    v->value.fixed = fixedvalue(newvalue);

  if(v->type == svt_mobj)
    v->value.mobj = MobjForSvalue(newvalue);


  if(v->type == svt_pInt)
    *v->value.pI = intvalue(newvalue);

  if(v->type == svt_pString)
    {
      // free old value
      free(*v->value.pS);

      // dup new string
      
      *v->value.pS = strdup(stringvalue(newvalue));
    }

  if(v->type == svt_pFixed)
    *v->value.pFixed = fixedvalue(newvalue);
  
  if(v->type == svt_pMobj)
    *v->value.pMobj = MobjForSvalue(newvalue);
  
  if(v->type == svt_function)
    script_error("attempt to set function to a value\n");

}
Example #2
0
// set a variable to a value from an svalue_t
void svariable_t::setvalue(svalue_t newvalue)
{
  if (killscript) return;  // protect the variables when killing script
  
  if (type == svt_const)
    {
      // const adapts to the value it is set to
      type = newvalue.type;

      // alloc memory for string
      if(type == svt_string)   // static incase a global_script var
	value.s = (char *)Z_Malloc(256, PU_STATIC, 0);
    }

  switch (type)
    {
    case svt_int:
      value.i = intvalue(newvalue);
      break;
    case svt_string:
      strcpy(value.s, stringvalue(newvalue));
      break;
    case svt_fixed:
      value.i = fixedvalue(newvalue).value();
      break;
    case svt_actor:
      value.mobj = MobjForSvalue(newvalue);
      break;
    case svt_pInt:
      *value.pI = intvalue(newvalue);
      break;
    case svt_pString:
      // free old value
      free(*value.pS);
      // dup new string
      *value.pS = strdup(stringvalue(newvalue));
      break;
    case svt_pFixed:
      *value.pFixed = fixedvalue(newvalue);
      break;
    case svt_pActor:
      *value.pMobj = MobjForSvalue(newvalue);
      break;
    case svt_function:
      script_error("attempt to set function to a value\n");
    }
}