Hello bupaje. hope the learning goes good
Enums for Lite-C are on the forecast page, which means they're going to be supported soon. In the meantime, the manual says to use Defines as a workaround..
so this:
Code:
Enum Colors
Red
Blue
Yellow
Green
End Enum
becomes this in lite-c
Code:
#define RED 0
#define YELLOW 1
#define GREEN 2
#define BLUE 3
In Lite-C you can group anything you want together using arrays. I used your wikipedia page and made a beaufort scale for you using a String array to store the descriptions of all beauforts and an Integer array to store their equivalent wind speeds in km/h. You could have made use of a struct as well for more ogranization, but it wouldn't eliminate the need for arrays.
Code:
#include <acknex.h>
#include <default.c>
var vGlobal_Wind_Speed;
STRING* sMessage = "";
PANEL* pDisplay =
{
digits (35, 10, "Global Wind Speed: = %0.f", "Arial#16b", 1, vGlobal_Wind_Speed);
digits (35, 70, "Object 1: = %s", "Arial#16b", 1, sMessage);
flags=VISIBLE;
}
#define LOW_WIND 0
#define HIGH_WIND 120
#define TENTH_OF_SECOND 0.1
//String Array. Initially emtpy
STRING* Beaufort[13]; //0 to 12
//Wind Speeds array: km per h wind speeds for each of the 12 beauforts
int WindSpeedsInKm[13] = { 0, 6, 11, 19, 29, 39, 50, 62, 75, 87, 102, 119, 120};
int WindSpeedToBeaufort(var WindSpeed)
{
int i;
for (i=0; i<13; i++)
if (WindSpeedsInKm[i]>=WindSpeed) return(i);
}
function BeaufortScale_init()
{
Beaufort[0]="Calm";
Beaufort[1]="Light air";
Beaufort[2]="Light breeze";
Beaufort[3]="Gentle breeze";
Beaufort[4]="Moderate breeze";
Beaufort[5]="Fresh breeze";
Beaufort[6]="Strong breeze";
Beaufort[7]="Moderate gale";
Beaufort[8]="Fresh Gale";
Beaufort[9]="Strong gale";
Beaufort[10]="Storm";
Beaufort[11]="Violent storm";
Beaufort[12]="Hurricane";
}
function UpdateWindDescription()
{
while (1)
{
str_cpy(sMessage,Beaufort[WindSpeedToBeaufort(vGlobal_Wind_Speed)]);
wait(1);
}
}
function main()
{
// initialize display
video_mode = 6;
screen_color.blue = 150;
BeaufortScale_init();
UpdateWindDescription();
while (1)
{
for (vGlobal_Wind_Speed=LOW_WIND; vGlobal_Wind_Speed<HIGH_WIND; vGlobal_Wind_Speed++)
wait(-TENTH_OF_SECOND);
for (vGlobal_Wind_Speed=HIGH_WIND; vGlobal_Wind_Speed>LOW_WIND; vGlobal_Wind_Speed--)
wait(-TENTH_OF_SECOND);
}
}
This script contains many more new things from the old one i've posted, but the problem (creating a beaufort scale), was more complicated as well. I'll very briefly describe how that script works, but try to run it on your pc, study how everything works, and let me know if u have trouble
In the main function, i now call another function called 'BeaufortScale_init' that enters string names in our Befaurt string array called: "Beaufort". We can now exchange a beaufort number with its description, since if we type: "Beaufort[4]" anywhere in our code, we'll get "Moderate breeze", etc. Also, i could have avoided using a different function and instead enter all strings inside the main function, but in sake of organization, using a function makes sense in this case.
You'll notice that the UpdateWindDescription function which is also called by main, has an infinite while loop in it, and a wait(1) instruction at the end. This means that everything inside that while loop will run for every single frame of our program(in other words, everything inside the while loop will get executed more than 60 times every second, depending on your FPS). In this case, it makes sure that the sMessage string which is displayed in the PANEL always contains the string which matches the Beaufort description of the current wind speed.
str_cpy(sMessage,Beaufort[WindSpeedToBeaufort(vGlobal_Wind_Speed)]);This is the harder line in the script, so i'd expect you'd need to study it for some time before you get how it works. When you do however, you'll learn quite a lot about lite-c.
Like I mentioned before, if you type str_cpy(sMessage,Beaufort[4]);, SMessage will become "Moderate breeze", but here instead of
4, we see:
WindSpeedToBeaufort(vGlobal_Wind_Speed). This is a function which returns an integer value. So When Lite-C will encounter this, it will run that function, check the value it returns and replace
WindSpeedToBeaufort(vGlobal_Wind_Speed) with that value. This 'WindSpeedToBeaufort' function converts Wind Speed to Beaufort, by taking the Global Wind_Speed as a parameter, and using the WindSpeedsInKm Integer Array to return the corresponding beaufort. The WindSpeedsInKm array has been filled with values taken from the wiki page. You know how a for loop works, so you should be able to decypher how the 'WindSpeedToBeaufort' function actually works.
Remember that the vGlobal_Wind_Speed value keeps increasing/decreasing from 0 to 120 from the older script, so the newer script constantly updates the sMessage with its corresponding beaufort description. The program constantly converts Wind Speed to Beaufort, and Beaufort to Description, to show the corresponding message in the panel. If you want to mess around with it, try to also show the current Beaufort number in the panel as well.
Cheers,
Aris