HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: [Resolved] Testing if an enumeration key is defined in the DOM editor via script  (Read 3598 times)

Azzerhoden

  • General Accounts
  • *
  • Posts: 42
  • Midnight General
    • View Profile

Apologies if this is listed somewhere easily found, but I am struggling to find the right search terms.

In essence, I am building some scripts to test my entered functionality using the command line.  One of the commands is to add a value into a Lookup List using an enumeration as the key.  Before I try to add it, I want to test whether I have defined the enumeration, giving my lack of proficiency at typing.

After I have verified that the entered text matches a defined enumeration value, that I'll use the "has" operator to test whether it has already been entered, but I am stumped as to how to test for a correctly entered enumeration key.

Down the road I planned on transitioning these enumerations into constants, so if this is not possible I'll go ahead and make the transition now.  Actually, not sure how I would test for whether a constant was defined either though.   ;D


Thanks in advanced!
« Last Edit: Nov 20, 12, 08:05:11 PM by Azzerhoden »
Logged

Azzerhoden

  • General Accounts
  • *
  • Posts: 42
  • Midnight General
    • View Profile

Would the None operator work for this?  Using an example from the wiki

: ced "river_states"; "empty" "full"

Would the following test be correct?  Not at home where I can test this in the script editor.

if river_states.empty = None
----  throw an error
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.

I am not logged in right now, but I know there is a external function for getting the list of values in a given enum. Search the  _ExternalFunctions script.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile

easiest way would be to use:
Code: (hsl) [Select]
GetEnumValues(enumName as String) as List of String
then iterate through the list comparing your entry to each string in the list.
If you don't fine one, it isn't valid.
« Last Edit: Nov 20, 12, 05:04:30 PM by Jrome90 »
Logged

TGSRofar

  • General Accounts
  • *
  • Posts: 153
    • View Profile

Don't need to iterate through the list.  Just use the list utils function...name is something like ListOfStringHasString.
Logged
Ron Farrell
Lead Programmer
Triad Game Studios

Azzerhoden

  • General Accounts
  • *
  • Posts: 42
  • Midnight General
    • View Profile

Perfect!  Thanks everyone! 
Logged

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile

Don't need to iterate through the list.  Just use the list utils function...name is something like ListOfStringHasString.
That is definitely a much cleaner way to do it.
Logged

Azzerhoden

  • General Accounts
  • *
  • Posts: 42
  • Midnight General
    • View Profile

It turns out it is even simpler.  In the strutils script is a function named IsValidEnumValue.

The function code is
Code: [Select]
public function IsValidEnumValue(enumType as String, testValue as String) as Boolean
  // lets you knwo if testValue is valid for the specified enumType
  enumValues as List of String = GetEnumValues(enumType)
  foreach enumVal in enumValues
    if ToLower(enumVal) == ToLower(testValue)
      return true
    .
  .
  return false
.

And to use my previous example, the way to call it is
Code: [Select]
: ced "river_states"; "empty" "full"

if strutils:IsValidEnumValue("river_states","empty")
--- do something useful since it exists.

Thanks again for pointing me in the right direction!
« Last Edit: Nov 20, 12, 08:39:13 PM by Azzerhoden »
Logged

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile

Are enum values case-sensitive?
Logged

Azzerhoden

  • General Accounts
  • *
  • Posts: 42
  • Midnight General
    • View Profile

Tested this as well, and the are not.
Logged