I have been reading a lot about conditional statements in BF1942 lately. Using 4CentShy's website (http://www.velotech.net/battlefield/tutorials.php) has helped me greatly in understanding the basics of using conditional statements in BF1942.
I am now trying to create my own scripts for basic stuff such as verifying mod versions for clients (map side) and stuff. Things like this require basic if/else/elseif statements and are rather simple to do. I however know absolutely nothing about coding and would like to build more complex scripts. The current script I am working on evaluates what the server round time setting has been set to and prints a debug message to the screen (client side) depending on what the time has been set to. Here is the code:
Code: Select all
Var v_time
Const c_time1 = 3600
Const c_time2 = 1800
Const c_time3 = 900
Const c_time4 = 450
game.serverGameTime -> v_time
if v_time < c_time1
debug.debugOutputMessage "Test 1" 1
elseif v_time < c_time2
debug.debugOutputMessage "Test 2" 1
elseif v_time < c_time3
debug.debugOutputMessage "Test 3" 1
elseif v_time < c_time4
debug.debugOutputMessage "Test 4" 1
endIf
I know the coding in the above example is completely wrong, as in all cases, the returned debug message will always be "Test 1", because the first if statement will always be true. Setting the variables to something like c_time1 < v_time < c_time2 is unfortunately not supported by the game (the console says the boolean syntax is incorrect).
There is the option to use the Utils.expr command, but I have no idea how it works even after having read 4CentsShy's explanation about it. Here is a script that he made that uses Utils.expr, which compares variables between them using operators like <, >, <=, =>, &, | and !=:
Code: Select all
Var v_debug
Var v_urg
Var v_spawn
Var v_strat
Var v_sai
Var v_bot
Var v_sense
Var v_areas
Var v_none
Var v_botspawn
game.showAIStats -> v_debug
ai.showStrategicAreas -> v_areas
ai.showBotStats -> v_bot
ai.showBotSense -> v_sense
ai.showBotSpawnCoord -> v_spawn
ai.showBotUrgencies -> v_urg
ai.showStrategies -> v_strat
ai.showSAIStats -> v_sai
Utils.expr v_urg | v_spawn -> v_none
Utils.expr v_none | v_strat -> v_none
Utils.expr v_none | v_sai -> v_none
Utils.expr v_none | v_bot -> v_none
Utils.expr v_none | v_sense -> v_none
Utils.expr v_none | v_areas -> v_none
Utils.expr ! v_none -> v_none
Utils.expr ! v_spawn -> v_botspawn
Utils.expr v_bot & v_botspawn -> v_botspawn
game.showAIStats 1
game.enableFreeCamera 1
if v_debug == 0
debug.debugOutputMessage "Show AI Stats is ON" 1
ai.showBotUrgencies 0
ai.showBotSpawnCoord 0
ai.showStrategies 0
ai.showSAIStats 0
ai.showBotStats 0
ai.showBotSense 0
ai.showStrategicAreas 0
elseif v_none
debug.debugOutputMessage "AI Strategic Area debugging is ON" 1
ai.showStrategicAreas 1
elseif v_areas
debug.debugOutputMessage "AI Bot Stats debugging is ON" 1
ai.showStrategicAreas 0
ai.showBotStats 1
elseif v_botspawn
debug.debugOutputMessage "AI Bot Spawn debugging is also ON" 1
ai.showBotSpawnCoord 1
elseif v_spawn
debug.debugOutputMessage "AI Bot Sense debugging is ON" 1
ai.showBotStats 0
ai.showBotSpawnCoord 0
ai.showBotSense 1
elseif v_sense
debug.debugOutputMessage "AI Bot Urgency debugging is ON" 1
ai.showBotSense 0
ai.showBotUrgencies 1
elseif v_urg
debug.debugOutputMessage "AI Strategy debugging is ON" 1
ai.showBotUrgencies 0
ai.showStrategies 1
elseif v_strat
debug.debugOutputMessage "AI SAI debugging is ON" 1
ai.showStrategies 0
ai.showSAIStats 1
elseif v_sai
debug.debugOutputMessage "AI debugging is now OFF" 1
game.showAIStats 0
ai.showSAIStats 0
endif
tl;dr: Just use this thread to share your knowledge about conditionals in BF1942. Apparently there are more possibilities than just using if/else/elseif as commands. The while loop also seems to work (tested in a BF1942 map, it works but I don't know how to use it properly) and return, but I'm not sure what else also works.