Always snap to grid
Difference between revisions of "Compiler issues"
From Unreal Wiki, The Unreal Engine Documentation Site
(New page that explains parsing issues such as defaultproperties{ and comments) |
(→Parsing Issues) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 4: | Line 4: | ||
'''Comment''' ''Issues related to the [[comments]]'' | '''Comment''' ''Issues related to the [[comments]]'' | ||
<br> | <br> | ||
− | {{ | + | :Having an end of multi-line comment proceeded by a line comment on the same line. |
+ | {{CorrectWrong|<uscript> | ||
+ | /* if(!bUseForVehicles) | ||
+ | return Super.DamageTaken(Enemy, Injured); | ||
+ | else{//Branch4: Do vehicle code here, optimized?} | ||
+ | */</uscript><uscript>/*local int LogInitHealth;*/ /*, LogDamage, LogConversion;*/ | ||
+ | </uscript>|<uscript>/* if(!bUseForVehicles) | ||
+ | return Super.DamageTaken(Enemy, Injured); | ||
+ | else{//Branch4: Do vehicle code here, optimized?}*/</uscript><uscript>/*local int LogInitHealth;*//*, LogDamage, LogConversion;*/ | ||
+ | </uscript>}} | ||
'''DefaultProperties''' ''Issues related to the [[defaultproperties]] block'' | '''DefaultProperties''' ''Issues related to the [[defaultproperties]] block'' | ||
Line 10: | Line 19: | ||
:Placing a { on the same line of the defaultproperties declaration will cause the parser to skip the defaultproperties block thus :all of your default values will not be compiled, to get around this is easy just place the { on the next line!. | :Placing a { on the same line of the defaultproperties declaration will cause the parser to skip the defaultproperties block thus :all of your default values will not be compiled, to get around this is easy just place the { on the next line!. | ||
− | < | + | {{CorrectWrong|<uscript> |
− | { | + | defaultproperties |
− | | | + | { |
− | + | }</uscript>|<uscript> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | <uscript> | + | |
defaultproperties{ | defaultproperties{ | ||
+ | }</uscript>}} | ||
+ | |||
+ | '''Switch''' ''Issues related to the [[switch]] block'' when attempting to access DefaultProperties from a static function. | ||
+ | <br> | ||
+ | :Using the syntax Default.Identifier (to resolve a DefaultProperties reference from a static function) within a [[switch]] block confuses the compiler, which assumes the script has an error, and suggests 'default:', as in ''the default case'' for a switch statement. The error message is ''Error, Missing ':' in 'Default''. See examples for some workarounds. | ||
+ | |||
+ | {{CorrectWrong|<uscript> | ||
+ | // A workaround is necessary. | ||
+ | // Example using the class name directly.. | ||
+ | case 1: | ||
+ | Class'GameMessage'.Static.CallMe (); | ||
+ | break; | ||
+ | // ..or an if-else block to replace the switch-case statement.. | ||
+ | // ..or a local proxy variable: | ||
+ | static function Test (int Index) | ||
+ | { | ||
+ | local class<LocalMessage> ClassNameWorkaround; | ||
+ | ClassNameWorkaround = Default.ClassName; | ||
+ | // ... | ||
+ | case 1: | ||
+ | ClassNameWorkaround.Static.CallMe (); | ||
+ | break; | ||
+ | // ... | ||
} | } | ||
− | </uscript> | + | </uscript>|<uscript> |
+ | var class<LocalMessage> ClassName; | ||
− | + | static function Test (int Index) | |
− | + | ||
− | + | ||
{ | { | ||
+ | switch (Index) | ||
+ | { | ||
+ | case 1: | ||
+ | Default.ClassName.Static.CallMe (); | ||
+ | break; | ||
+ | |||
+ | default: | ||
+ | break; | ||
+ | } | ||
} | } | ||
− | </uscript> | + | |
− | |-} | + | DefaultProperties |
− | </ | + | { |
+ | ClassName = Class'GameMessage' | ||
+ | } | ||
+ | </uscript>}} | ||
+ | |||
+ | |||
+ | '''DefaultProperties''' ''Issues related to the [[defaultproperties]] block'' and the mathematical syntax for representing negative numbers. No warnings from the compiler. | ||
+ | <br> | ||
+ | :In mathematics, a negative number is sometimes represented in parenthesis, as in the expression 1 + (-1). The parenthesis are not recognized, and thus the value becomes 0.0f (default-initialized). | ||
+ | |||
+ | {{CorrectWrong|<uscript>var float A; | ||
+ | |||
+ | DefaultProperties | ||
+ | { | ||
+ | A = -1.0f | ||
+ | }</uscript>|<uscript>var float A; | ||
+ | |||
+ | DefaultProperties | ||
+ | { | ||
+ | A = (-1.0f) // A is 0.0f | ||
+ | }</uscript>}} | ||
+ | |||
+ | |||
+ | '''DefaultProperties''' ''Issues related to the [[defaultproperties]] block'' and const values. No warnings from the compiler. | ||
+ | <br> | ||
+ | :A const value would appear default-initialized (0.0f, 0, false) when used in a [[defaultproperties]] block. | ||
+ | |||
+ | {{CorrectWrong|<uscript>var float A; | ||
+ | |||
+ | DefaultProperties | ||
+ | { | ||
+ | A = 2.71828f | ||
+ | }</uscript>|<uscript>var float A; | ||
+ | const C = 2.71828f; | ||
+ | |||
+ | DefaultProperties | ||
+ | { | ||
+ | A = C // A is 0.0f | ||
+ | }</uscript>}} |
Latest revision as of 20:02, 12 November 2011
Like any other compiler there are issues with the parsing therefor this page exists to mention those common issues and how to get around them.
Parsing Issues[edit]
Comment Issues related to the comments
- Having an end of multi-line comment proceeded by a line comment on the same line.
Correct and Wrong example
Correct |
Wrong |
/* if(!bUseForVehicles)
return Super.DamageTaken(Enemy, Injured);
else{//Branch4: Do vehicle code here, optimized?}
*/ /*local int LogInitHealth;*/ /*, LogDamage, LogConversion;*/ |
/* if(!bUseForVehicles)
return Super.DamageTaken(Enemy, Injured);
else{//Branch4: Do vehicle code here, optimized?}*/ /*local int LogInitHealth;*//*, LogDamage, LogConversion;*/ |
DefaultProperties Issues related to the defaultproperties block
- Placing a { on the same line of the defaultproperties declaration will cause the parser to skip the defaultproperties block thus :all of your default values will not be compiled, to get around this is easy just place the { on the next line!.
Correct and Wrong example
Correct |
Wrong |
defaultproperties { } |
defaultproperties{ } |
Switch Issues related to the switch block when attempting to access DefaultProperties from a static function.
- Using the syntax Default.Identifier (to resolve a DefaultProperties reference from a static function) within a switch block confuses the compiler, which assumes the script has an error, and suggests 'default:', as in the default case for a switch statement. The error message is Error, Missing ':' in 'Default. See examples for some workarounds.
Correct and Wrong example
Correct |
Wrong |
// A workaround is necessary. // Example using the class name directly.. case 1: Class'GameMessage'.Static.CallMe (); break; // ..or an if-else block to replace the switch-case statement.. // ..or a local proxy variable: static function Test (int Index) { local class<LocalMessage> ClassNameWorkaround; ClassNameWorkaround = Default.ClassName; // ... case 1: ClassNameWorkaround.Static.CallMe (); break; // ... } |
var class<LocalMessage> ClassName; static function Test (int Index) { switch (Index) { case 1: Default.ClassName.Static.CallMe (); break; default: break; } } DefaultProperties { ClassName = Class'GameMessage' } |
DefaultProperties Issues related to the defaultproperties block and the mathematical syntax for representing negative numbers. No warnings from the compiler.
- In mathematics, a negative number is sometimes represented in parenthesis, as in the expression 1 + (-1). The parenthesis are not recognized, and thus the value becomes 0.0f (default-initialized).
Correct and Wrong example
Correct |
Wrong |
var float A; DefaultProperties { A = -1.0f } |
var float A; DefaultProperties { A = (-1.0f) // A is 0.0f } |
DefaultProperties Issues related to the defaultproperties block and const values. No warnings from the compiler.
- A const value would appear default-initialized (0.0f, 0, false) when used in a defaultproperties block.
Correct and Wrong example
Correct |
Wrong |
var float A; DefaultProperties { A = 2.71828f } |
var float A; const C = 2.71828f; DefaultProperties { A = C // A is 0.0f } |