Page 1 of 1

Function return stuff

PostPosted: Wed Aug 24, 11 1:40 pm
by Cozmo
This stems from the other thread, but warrants its own topic imo because it's a specific problem (for archival reasons I guess).

Trying to access variables from within a struct that's too big to do it directly, so having to use a function. It compiles fine, but I'm not too sure it's actually working. I'd use a debug to find out, but it'd have to be after the return, so would do nothing. Can anyone see anything wrong with this? Thanks in advance.

I'll post the entire mod code next time, if that helps.

Trying to set an int inside an array inside a struct, with MPCS being the other class:
Code: Select all
MPCS.SetCondition(talkingto, MissionNumber, Interactions[MPCS.GetMissionCondition(TalkingTo, MissionNumber)].E_SetMissionCondition);


Function from the other class (MPCS) ... (paranoid the return; actually stops it - not too sure how it works)
Code: Select all
struct Storagez
{
   Var DeusExPlayer DXP;
   var int Condition[40];
};
var() localized Storagez StoredVars[40];

...

function SetCondition(DeusExPlayer DEP, int MissionNumbah, int ChangeTo)
{
   local int i;

   for (i=1; i<40; i++)
   {
      if(StoredVars[i].DXP == DEP)
      {
         StoredVars[i].Condition[MissionNumbah] = ChangeTo; //not sure this is being set
      }
   }
}

PostPosted: Tue Nov 22, 11 1:03 am
by EXetoC
I'm not sure what you mean by having to do debug stuff after the function returns. The array element should be set, and you can verify this by inserting this just after the assignment in the if-statement
Code: Select all
assert(StoredVars[i].Condition[MissionNumbah] == ChangeTo);


You should also replace this
Code: Select all
i=1; i<40; i++

With this
Code: Select all
i=1; i <ArrayCount(StoredVars); i++

So that you don't have to change it every time you decide to change the size of the array, thus preventing potential bugs from appearing.