I know some languages do not support switch statement comparisons for string / literal values, so the only way to go about comparing strings for state machines is to compare them with if...else statements.
Maybe this will change for some programming language standards in the future, where the programming language doesn't support switch state string comparison?
I almost with that there were 'meta-programming languages' or something where it's the same language, but with fixes that compiles down to the original langauge
I know what lisp macros are, but what I was thinking would be like if C++ was a compile-to-c language that wasn't intended to stand on it's own, or something like that
I think it should be more object oriented. The property Witnessed should not be a string but instead a WitnessedType class. Here's what I was thinking:
public abstract class WitnessedType
{
public abstract string Label { get; }
public abstract string GameOverCause { get; }
}
So an abstract class type that all witness types inherit. An example concrete witness type would be:
public class InsanityWitnessedType : WitnessedType
{
public override string Label => "Teacher Insanity Reaction";
public override string GameOverCause => "Insanity";
}
Then the Witnessed property would change from type string to type WitnessedType and the entire if/if else/else block could be boiled down to this:
if (!this.WitnessedCorpse)
{
this.Subtitle.UpdateLabel(this.Witnessed.Label, 1, 6.0f);
this.GameOverCause = this.Witnessed.GameOverCause;
}
There are a couple special cases which aren't covered with this approach but they could be by adding a virtual method for triggering the label and game over cause to the WitnessedType class and then overriding it in those special cases.
The next fix would be fixing the Label and GameOverCause property as it currently seems to pass in a key as a string which then gets a proper sentence from a dictionary somewhere. "Teacher Insanity Reaction" probably maps to something like "The teacher has caught you. You have been arrested." that then gets displayed to the player.
28
u/asperatology Sep 21 '16
I know some languages do not support switch statement comparisons for string / literal values, so the only way to go about comparing strings for state machines is to compare them with if...else statements.
Maybe this will change for some programming language standards in the future, where the programming language doesn't support switch state string comparison?
3
u/AnxiousAbigail01 Dec 19 '21
this screams "ENUMS AND SWITCH STATEMENTS!"
1
u/peepeeweewee69 Mar 09 '17
looks fine to [me] (http://2static2.fjcdn.com/comments/Ahegao+_0eaf3dbc104f428d0d2c548c7a62c78b.jpg)
1
u/[deleted] Sep 22 '16 edited Jul 27 '17
[removed] — view removed comment