SRL Archive - MSI Suggestions

Using functions when appropriate.


Sir R. M8gic1an

2010-03-14 07:19:17

Okay, I was going through the include today, particularly the mainloop, and there was something that just screamed FUNCTIONS at me. :)


MSI_Debug('MSI_MainLoop', 'Failed to bank materials!', Debug_PlayerActions);
Players[CurrentPlayer].Active := False;
ProgressReport;

MSI_Debug('MSI_MainLoop', 'Failed to walk to bank!', Debug_PlayerActions);
Players[CurrentPlayer].Active := False;
ProgressReportArray[CurrentPlayer].FalseReason := 'Failed to walk to bank';
Players[CurrentPlayer].Integers[P_LOC] := LOC_LOST;
ProgressReport;

MSI_Debug('MSI_MainLoop', 'Failed to perform skill!', Debug_PlayerActions);
Players[CurrentPlayer].Active := False;
ProgressReportArray[CurrentPlayer].FalseReason := 'Failed to perform skill: ' + IntToStr(CurrentSkill);
ProgressReport;


Procedure UnsetPlayer(func, reason: string);
begin
MSI_Debug(func, reason, Debug_PlayerActions);
Players[CurrentPlayer].Active := False;
ProgressReportArray[CurrentPlayer].FalseReason := reason;
ProgressReport;
LogOut;
end;


Do not replace directly the fail walks. Notice this part is not included in the new procedure:
Players[CurrentPlayer].Integers[P_LOC] := LOC_LOST;


Today's Lesson: Whenever code is repeated, make a function for it.

~RM

Coh3n

2010-03-14 11:44:58

Yeah, I didn't like how it was repeated either. I just figured it's be easiest to follow. I didn't even think of using another function. Also, why not set the player's location to lost?

Sir R. M8gic1an

2010-03-14 11:53:07

From: Coh3n
Yeah, I didn't like how it was repeated either. I just figured it's be easiest to follow. I didn't even think of using another function. Also, why not set the player's location to lost?


Because you didn't change loc everytime, therefore it wasn't repeated :p
Notice that I didn't go very in-depth into the code to actually decide if loc should be changed every time or not.

~RM

Coh3n

2010-03-14 11:59:37

From: Rasta Magician
Because you didn't change loc everytime, therefore it wasn't repeated :p
Notice that I didn't go very in-depth into the code to actually decide if loc should be changed every time or not.

~RM

Oh haha, I thought you meant do leave it out altogether. :p

The reason I changed it was for the progress report. Instead of saying it's at the trees when it probably isn't (because the walking failed), it would be better to say the player is lost.