In order to make reverse engineering more difficult for compiled projects, Construct minifies and obfuscates the final JS code. As a result, the names of Object Types are not preserved after export. Thus, it is not possible to create an object type by name at run-time.

One possible solution to this is to write a "CreateObject" function to handle spawning of all objects. Spawn by name allows a developer to create more modular code, eg, easily switch Enemy.Projectile = "HomingMissile" or Enemy.Projectile = "RegularBullet", assuming these are Object Type names. This keeps the code cleaner. Because creation is happening within a function, subsequent pick statements will work properly without exception.

SpawnByName.png
Figure 1: Spawn Function



Note that in each ObjectName conditional, the UID is explicitly set to variable RetUID that is returned by the function.