Question about the while/endWhile loop

Ask questions, discuss ideas, get answers
Post Reply
Diamondback
Posts: 589
Joined: Mon Oct 01, 2012 3:13 pm
Location: Canada
Contact:

Question about the while/endWhile loop

Post by Diamondback »

Hi all.

I am currently trying to make a custom script that can execute continuously, with no client input, from the moment the map is loaded to the end of a round.

In BF1942, my research has led me to understand there are two ways CON file scripts can be executed: only once at the beginning of a round and by client input, by binding a script to a keyboard or mouse key.

The first method of executing a CON file is done right after a map is done loading. If conditional statements are used in a custom CON file, the conditions in that CON file are checked only once right after map load and at no other moment during the rest of the round. This is good if you want to check if a condition is met for variables that do not change during the whole length of a round, like the game mode or the mod in which the map runs (obviously, when you play a certain game mode it does not magically change to another mode during the round). It does not work for variables that can change during a round (which I will call "dynamic" variables for the purpose of this thread), like a player's health.

The second method is far more interesting and allows the client to check if a condition is met at any moment during the round. Dynamic variables, such as a player's health or location, can be assigned to certain console commands and the outputs of these commands can be made available to the client after pressing a key which executes the console script. So with client input (ie, pressing a key), that client can check, for example, the status of his/her health at any moment during the round. The only problem with this method is that the script needs client input to work (the pressing of a key). What if we wanted to execute a script to check the status of these "dynamic" variables during the whole round? That is when the use of a while/endWhile loop could potentially solve this problem.

A while/endWhile loop checks if a conditions is true, and if it is, executes a chunk of code indefinetly until the condition no longer evaluates to true. So I decided to use a while/endWhile loop in a script I made so that it runs automatically from the moment the map loads and I spawn in the game until the end of the round. I made a script that checks what my player's health is in-game and returns that value as a percentage only my player can see. To my surprise, the while loop actually works as intended, but it does not run indefinetly as the game uses a "breaking" mechanism to stop the loop after the 1000th iteration of it. In other words, the while loop only works for a few seconds after the map has finished loading, then stops after looping for the 1000th time.

My question is, would there potentially be a way to make the while loop continue looping for the rest of the round, and not stop after the 1000th loop? I imagine it would require hacking the BF1942.exe. Could it be patched somehow to make the while loop a true while loop and not end after 1000 loops?
See my Strasbourg map project here.
Post Reply