After Flinx pointed out the difference between RawGet and HaveItem/HasItem, if you want to rather use HasItem/HaveItem option, then you could change the program a bit:
Code: Select all
Function AddHostSystem(versionname, SystemType, SystemSpecific)
t_HostSystems[LowerStr(versionname)] = {SystemType = SystemType, SystemSpecific = SystemSpecific}
EndFunction
AddHostSystem("AmigaOS3", "AOS", "AOS3")
AddHostSystem("AmigaOS4", "AOS", "AOS4")
AddHostSystem("AROS", "AOS", "AROS")
hha
AddHostSystem("MorphOS", "AOS", "MorphOS")
AddHostSystem("MacOS", "MacOS", "MacOS")
AddHostSystem("Win32", "W", "Win32")
Local Version = GetVersion().Platform
Version = LowerStr(Version)
Local SystemType = "Unknown"
Local SystemSpecific = "Unknown"
If HasItem(t_HostSystems, Version)
SystemType = t_Hostsystems[Version].SystemType
SystemSpecific = t_HostSystems[Version].SystemSpecific
EndIf
DebugPrint("Detected system type:", SystemType)
DebugPrint("Detected specific system:", SystemSpecific)
There are two differences in this:
Code: Select all
t_HostSystems[versionname] = {SystemType = SystemType, SystemSpecific = SystemSpecific}
has been changed into:
Code: Select all
t_HostSystems[LowerStr(versionname)] = {SystemType = SystemType, SystemSpecific = SystemSpecific}
Only difference is that instead of "versionname" it will first use "
LowerStr()" command to make the versionname into lower letters (Ie. "AbCdE", changed into "abcde"), which means that instead of having t_HostSystems["AmigaAOS3"] = {} it will now instead have t_HostSystems["amigaaos3"] = {}
Another change is that after taking
Code: Select all
Local Version = GetVersion().Platform
there is additional line of:
Meaning that when GetVersion gives Version something like "AmigaAOS3" it will change it into "amigaaos3".
reason for this is since most of time when you use Hollywood to search for tables "variablename" indices, like table["Item"], it will do so by using lower letters, but not always.
Sometimes it might treat "ITEM" and "item" as one and same, and sometimes it thinks them as two different things.
This is why
RawGet() was working and HasItem/HaveItem didn't in the original example.
RawGet was able to look for "AmigaAOS3" item specifically, while HasItem/HaveItem weren't able to look for "AmigaAOS3".
If you remove the line "Version = LowerStr(Version)", then you will encounter another problem.
For without that line we are at situation where the Table Item is:
"t_HostSystems["amigaaos3"]"
and the "Version" is "AmigaAOS3".
When using HasItem/HaveItem on the IF check:
Code: Select all
If HasItem(t_HostSystems, Version)
it actually works right, since HasItem/HaveItem will automatically be looking for lower letters version. That while "Version" is "AmigaAOS3" HasItem/HaveItem is actually looking for "amigaaos3" instead, which matches with the current t_HostSystems item naming.
However, when inside that IF loop:
Code: Select all
If HasItem(t_HostSystems, Version)
SystemType = t_Hostsystems[Version].SystemType
SystemSpecific = t_HostSystems[Version].SystemSpecific
EndIf
problem is that at point "SystemType = t_Hostsystems[Version].SystemType" Hollywood is looking for "AmigaAOS3" entry, and cant find it, because there is only "amigaaos3" entry existing.
Due to Hollywood in some cases being case insensitive, and sometimes case sensitive, I recommend doing it this way that I am showing now, as to show everything into lower letters, since that is the way to cause least problems.
Notice to use lowercase letters, not uppercase letters, because once again, if you have entry t_HostSystems["AMIGAAOS3"], and then you try using HasItem/HaveItem with "AMIGAAOS3", it will be looking for "amigaaos3" instead, and fail, since it cant find one.
Also, I recommend using HasItem/HaveItem instead of RawGet, simply because if you do some error in the code where you are accidentally using UpperCase letters, like "AmigaAOS3", then HasItem/HaveItem has better chance to fail and you can notice that error.
RawGet is basically quite dangerous to use, since without doing any changes into lower or uppercase letters, you can in the worse case have a mix of lowercase and uppercase letters. As in, You have Item "AmigaAOS3", which needs to be searched precisely with "AmigaAOS3".
For example, if Hollywoods next version decides to change the naming to "AmigaAos3" instead, then RawGet will fail, since it cant find that entry.
Instead, if you are doing like I have shown in this example, as in changing everything to lower letter, then even if Hollywood would change "AmigaAOS3" to "AmigaAos3", it would still work as usual.
Also notice that when making the t_HostSystems table, I am doing the change to Lower Letters inside the Function:
Code: Select all
Function AddHostSystem(versionname, SystemType, SystemSpecific)
t_HostSystems[versionname] = {SystemType = SystemType, SystemSpecific = SystemSpecific}
EndFunction
This is so that when I am using the "AddHostSystem" command, I don't need to worry about Uppercase or Lowercase letters, but can simply use "AmigaAOS3" which makes it easier to read the code, although inside the function this is changed into "amigaaos3".
Similarly when you get the
GetVersion().Platform, remember to change it instantly into lowercase version to avoid any problems. And Similarly if you for some reason want to manually compare for example the "AmigaAOS3", you could do it this way:
Code: Select all
IF Lowerstr("AmigaAOS3") = Version
and this way be able to yourself write a mix of upper and lowercase letters, even Hollywood would be dealing with lowercase versions in reality.
To put it short, always use lowercase letters to minimize the troubles coming from upper/lowercase letter conflicts.