From 30e67694e8f68aef32d708647a2635804f2951b1 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Wed, 10 Jan 2024 16:20:08 -0600 Subject: [PATCH] arrayobject helper commands getValueFromKey and getKeyFromValue. both look to the left or right hand entry for the other one example: %array.add("startPos","0 0 0 "); echo(">".%array.getValueFromKey("startPos")); > 0 0 0 --- Engine/source/console/arrayObject.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Engine/source/console/arrayObject.cpp b/Engine/source/console/arrayObject.cpp index bd3893ab0..60a36e9c9 100644 --- a/Engine/source/console/arrayObject.cpp +++ b/Engine/source/console/arrayObject.cpp @@ -600,6 +600,22 @@ DefineEngineMethod( ArrayObject, getIndexFromKey, S32, ( const char* key ),, return object->getIndexFromKey( key ); } +DefineEngineMethod(ArrayObject, getValueFromKey, const char*, (const char* key), , + "Search the array from the current position for the Key " + "@param value Array key to search for\n" + "@return Value of the first element found, or -1 if none\n") +{ + return object->getValueFromIndex(object->getIndexFromKey(key)).c_str(); +} + +DefineEngineMethod(ArrayObject, getKeyFromValue, const char*, (const char* key), , + "Search the array from the current position for the Value " + "@param value Array key to search for\n" + "@return Key of the first element found, or -1 if none\n") +{ + return object->getKeyFromIndex(object->getIndexFromValue(key)).c_str(); +} + DefineEngineMethod( ArrayObject, getValue, const char*, ( S32 index ),, "Get the value of the array element at the submitted index.\n" "@param index 0-based index of the array element to get\n"