Skip to content

WeiDU and "breaking" out of arrays

BubbBubb Member Posts: 1,005
Hello again! I am fairly new to WeiDU, though I have some hobbyist coding background that helps me grasp most things in the documentation. I am struggling with one concept, however, and that is WeiDU's flavor of array.

I'm sure I'm probably reinventing the wheel here, though I'm just trying to get a grasp on the fundamentals. I've written this function here:

/** * Patch function. Checks if a key is inside of an array. * INT_VAR key The key to check for. * STR_VAR array_name The name of the array to check. * RET result 1 if array contains key, 0 if array doesn't contain key. */ DEFINE_PATCH_FUNCTION ARRAY_CONTAINS_KEY INT_VAR key = 0 STR_VAR array_name = ~~ RET result BEGIN result = 0 PHP_EACH ~%array_name%~ AS array_key => array_value BEGIN PATCH_IF (array_key == key) BEGIN result = 1 ??? <-- I want to break out of the PHP_EACH here END END END

Does anyone know how I'd implement a conventional code-break at the marked line? I've thought of using a FOR loop and then shorting the increment variable, or perhaps a WHILE loop also using a "break" variable, though I cannot figure out how to get the size of an array - and thus I cannot set up either of these other cases. Any help would be greatly appreciated!

Comments

  • ArdanisArdanis Member Posts: 1,736
    edited February 2018
    PHP_EACH can't be stopped in the middle.

    If you need to retrieve value associated with the given key, you can do this:
    PATCH_IF VARIABLE_IS_SET $"%array_name%"("%key%") BEGIN
      value = $"%array_name%"("%key%")
      result = 1
      // etc.
    END
  • BubbBubb Member Posts: 1,005
    VARIABLE_IS_SET was exactly what I was missing, thanks!
Sign In or Register to comment.