EDIT: SEEMS THREAD MIGHT BE GETTING CLOSED, SO PLEASE REPLY HERE INSTEAD
https://www.frictionalgames.com/forum/thread-40412.html
just letting you people know the issue has been fixed.
When reading frictionals code however, I discovered a piece of code I initially thought was retarded, but upon closer inspection seemed to be a workaround for a tricky code issue, and I was wondering what the ideal way to implement something like it would have been. You can take a look at the actual code yourself in the 03_archives.hps, but in short it goes like this:
void CollideSecretBook(string &in asBook, string &in asCollideArea, int BookState)
{
AddTimer(asBook,20,"PushBackBook1"); //name of the timer(asTimer) = name of the book being pulled out(asBook)
}
PushBackBook1(string &in asTimer)
{
SetPropObjectStuckState(asTimer, -1); //Pushes the book back
AddTimer("2"+asTimer, 0.25f, "PushBackBook02"); //then just 0.25 seconds later the same book is put into the normal state.
}
PushBackBook2(string &in asTimer)
{
if(asTimer == "2SecretBook_1")
{
SetPropObjectStuckState("SecretBook_1", 0);
}
else if(asTimer == "2SecretBook_2")
{
SetPropObjectStuckState("SecretBook_2", 0);
}
else
{
SetPropObjectStuckState("SecretBook_3", 0);
}
}
Basically PushBackBook1 and PushBackBook2 do almost the same thing, but for some reason PushBackBook2 needs code for every single book while the other simply got the name of the book from the timer name.
The reason for this is that the timer that calls PushBackBook2, cant be named the same as the Book, since there's already a timer for PushBackBook1 with the very same name.
Hence the scripter had to rename the timer with the "2" in front, but the problem with doing this was that now he could not use the timer name anymore to pass on the name of the book, so instead of just writing:
SetPropObjectStuckState(asTimer, 0);
He had to go through and script for every single timer name
if(asTimer == "2SecretBook_1")
{
SetPropObjectStuckState("SecretBook_1", 0);
}
else if(asTimer == "2SecretBook_2")
{
SetPropObjectStuckState("SecretBook_2", 0);
}
else
{
SetPropObjectStuckState("SecretBook_3", 0);
}
This seems terribly messy, and I cant help but feel there has to be some way that the name of Book can be passed on directly from PushBackBook1 to PushBackBook2.
Any ideas?