Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
1 registered members (Grant), 999 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Help Burt Learn Lite-C [Re: Orange Brat] #166644
11/15/07 02:12
11/15/07 02:12
Joined: Aug 2002
Posts: 2,692
California, USA
bupaje Offline OP
Expert
bupaje  Offline OP
Expert

Joined: Aug 2002
Posts: 2,692
California, USA
Thanks for sharing. Got a bit of time tonight and going to continue my relentless picking at the code. It is just a learning exercise for me but I've daydreamed about several projects over the past few years I've been on the forums. A wind script is one of those and so it helps me to be motivated to study the lite-c after I get home at night. A "Hello World" script doesn't have the same motivating force.


Find me at: |Stormvisions| Twitter|
Re: Help Burt Learn Lite-C [Re: bupaje] #166645
11/15/07 03:55
11/15/07 03:55
Joined: Jul 2004
Posts: 1,205
Greece
LarryLaffer Offline
Serious User
LarryLaffer  Offline
Serious User

Joined: Jul 2004
Posts: 1,205
Greece
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


INTENSE AI: Use the Best AI around for your games!
Join our Forums now! | Get Intense Pathfinding 3 Free!
Re: Help Burt Learn Lite-C [Re: LarryLaffer] #166646
11/15/07 04:07
11/15/07 04:07
Joined: Aug 2002
Posts: 2,692
California, USA
bupaje Offline OP
Expert
bupaje  Offline OP
Expert

Joined: Aug 2002
Posts: 2,692
California, USA
Thanks very much Aris! This gives me a lot of interesting material to play with and pick at. This will keep me busy for a few days.


Find me at: |Stormvisions| Twitter|
Re: Help Burt Learn Lite-C [Re: bupaje] #166647
11/15/07 18:44
11/15/07 18:44
Joined: Aug 2000
Posts: 7,490
O
Orange Brat Offline

Senior Expert
Orange Brat  Offline

Senior Expert
O

Joined: Aug 2000
Posts: 7,490
Here's that file:

http://www.geocities.com/hainesrs/wind.wdl

It's a long one, and a conversion to Lite-C would do it good if for anything to more to do something about the large number of nested and non-nested IF statements. This was my very first contribution ever and a port of some free to use C++ code I found. It was a huge learning experience, so maybe someone can do something with it.

It doesn't actually move anything automatically (as some thought it did way back when I posted it years ago), you have to use a value that gets returned and use that to determine your movement behavior. I believe it's "w_speed_current" and "w_acceleration" which I used with the physics engine to move some hanging lights around with a wind.

Anyway, it does all kinds of stuff, and here's what I built into it...good luck with it if you decide to use it:

Code:

var w_power_factor = 2; /* DETERMINES WIND BEHAVIOR
1 = always strong gusts..no normal ones
2 = more frequent random strong gusts
3 = less frequent random strong gusts
4 = no strong gusts..always normal ones
5 = constant strong gust/hurricane..no calming
6 = no wind */




My User Contributions master list - my initial post links are down but scroll down page to find list to active links
Re: Help Burt Learn Lite-C [Re: Orange Brat] #166648
11/15/07 19:53
11/15/07 19:53
Joined: Aug 2002
Posts: 2,692
California, USA
bupaje Offline OP
Expert
bupaje  Offline OP
Expert

Joined: Aug 2002
Posts: 2,692
California, USA
Thanks Ryan. I'm just using this to learn at this point, but if nobody does anything with it before me (and I pick up enough skill with LiteC) I'd like to implement a couple ideas I've chewed on for a couple years - that includes a wind system. I'll be picking the forum brains for direction if I get that far. Thanks again for sharing.


Find me at: |Stormvisions| Twitter|
Page 2 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1