Morning all,
Been experiencing a small challenge and wanting to establish if it can be done this way, or if I am doing something wrong.
What I am trying to achieve is to pass the name of a table in some script that I have written as a string variable:
- Returns a argument#0 error when compiling
Table_Name = RECIPE;
Table_Name_Len = GetLengthOfTable(Table_Name);
- No error when compiling, however does not write value to table element.
Recipe_Value = 150;
Table_Name[0] = Recipe_Value ;
Can this be achieved ?
If I declare the actual name of the table. RECIPE[0] = Recipe_Value, the data is stored
All data types are matched.
Kind Regards
Robin
Welcome to the wonderful world of âNeeding to Use Pointersâ.
Basically what youâll do is to find the table by name using âGetPointerFromNameâ, with the name being the name of your recipe (Chili or somesuch), thatâll give you a pointer to the table. To use that pointer, youâll âdereferenceâ it by putting a * in front of it, which means âdo what Iâm asking with the thing pointed at by this pointer, not to the pointer itselfâ. So if you say â*mypointer = 12â, youâre not setting the pointer variable to 12, youâre setting the variable pointed to by the pointer to 12. Hope thatâs clearer than mud.
So hereâs the sample. Have a float table named âChiliâ defined, a string named âs_RecipeNameâ, a float named âf_RecipeValueâ, an int32 named âi_RecipeValueIndexâ, and that really fun and scary pointer named âtp_TablePointerâ with a pointer type of âFloat Tableâ, because thatâs what weâre going to ask it to point to.
// set up some variables for this test
s_RecipeName = âChiliâ;
i_RecipeValueIndex = 3;
f_RecipeValue = 25.4;
// get a pointer to the recipe table for your recipe
GetPointerFromName(s_RecipeName, tp_TablePointer);
// using the pointer, dereference it and pop a value in the right index
*tp_TablePointer[i_RecipeValueIndex] = f_RecipeValue;
If all goes well (and it did when I test ran it), your âChiliâ table should end up containing â25.4â in index 3. As a side note, you really really should check the pointer for NULL before you write something using it. I didnât do that here, because, well⌠Iâm lazy.
3 Likes
Hi Todd,
Thankyou for the advice and âpointingâ me in the right direction. Ha Ha
The way you have explained make sense and I will give it a go in the next day or two.
Appreciate the input !
Best Regards
Robin