Dont forget the while logic as well!
Here's what i know so far:
Nested ELSE's will result in bugged compiled code. Such as:
Code: Select all
if(...){
if(...){
// should work
}else{
// buggg
}
}
Not sure exactly if that will make bug, maybe the first IF needs else too.
I think it should be possible to fix that by writing own compiler, GTA2 should be able to read it correctly, if it was compiled correctly.
Here is the commented out code from my decompiler scr_functions.h, i have added there few lines:
[mis]
struct SCR_IF_JUMP {
SCR_CMD_FORMAT(
Uint16 logical_operator; // seems to be 0 for AND command and 1 for OR command.
Uint16 else_jump; // where will it jump if check was false.
);
};
string read_IF_JUMP(FPStruct ¶ms){
get_data(SCR_IF_JUMP, data);
if(params.header->return_value == 0 && data.logical_operator == 0){ // not sure about this.
return sprintf_str("ENDIF %s", hexdump(params,0).c_str());
}else{
return sprintf_str("%s", hexdump(params,1).c_str());
}
}
//LinkToFunc(SCRCMD_IF_JUMP, read_IF_JUMP);
//ZERO_PARAMS_LAYOUT_BOOL(NOT, "NOT"); // this will be wrapped around the previous
//comparison command or function with braces! (is not included atm because it causes
// parse errors in the compiler because its not wrapped around the IF's yet).
// TODO:
//TWO_PARAMS_LAYOUT(GOTO, sprintf_str("GOTO"); // correct struct, but format not
//figured out yet; probably not visible in code at all and used only in while loops etc.
[/mis]
GOTO's seem to be used with while loops. Or maybe with user defined functions as well?
For what i know, the IF command executes the boolean function, takes its return value, and then uses it as a parameter for the S_EQUAL_I etc functions. Same goes with NOT(), its just another function which only inverts the return value.
[mis]struct SCR_CMD_HEADER {
Uint16 cmd_this; // current pointer index.
Uint16 type; // which function type, PLAYER_PED etc.
Uint16 cmd_next; // next pointer index.
Uint16 return_value; // used by IF_JUMP's and boolean functions,
//seems to be return value for boolean functions, and endif marker for if_jumps (if zero).
};
[/mis]