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 1 of 2 1 2
Help Burt Learn Lite-C #166634
11/09/07 04:02
11/09/07 04:02
Joined: Aug 2002
Posts: 2,692
California, USA
bupaje Offline OP
Expert
bupaje  Offline OP
Expert

Joined: Aug 2002
Posts: 2,692
California, USA
Or I'll whine until you get fed up. On the plus side I won't post in the Lite-C forums until my questions are less stupid.

Can anyone look at this and tell me why I can't get the value for sMessage to print? Be patient with me as I haven't even looked at programming in ages and last that I did was BASIC. This is a nonsense program , just trying to understand the structure and such.


#include <acknex.h>
#include <default.c>

/* Declare Variables */

var vGlobal_Wind_Speed;
var vLocal_Wind_1;
var vObj1=1;
STRING* sMessage;

function global_wind()
{
// Generate Global Wind Values


vGlobal_Wind_Speed = 50;

}

function local_wind()
{
// Generate Local Wind Values

//get global wind and adjust by local conditions

vLocal_Wind_1 = (vGlobal_Wind_Speed / 2);
sMessage = "Windy!";
return sMessage;

}

function display_results()
{

PANEL* pDisplay =
{
digits (35, 10, "Global Wind Speed: = %0.f", "Arial#16b", 1, vGlobal_Wind_Speed);
digits (35, 30, "Local Wind 1: = %0.f", "Arial#16b", 1, vLocal_Wind_1);
digits (35, 70, "Object 1: = %s", "Arial#16b", 1, sMessage);
flags = VISIBLE;
}
}

function main()
{
var temp_counter=0;

// Initialize Display
video_mode = 6;
screen_color.blue = 150;


// Check if wind engine is enabled


while (temp_counter<1)
{

global_wind();
local_wind();
display_results();
temp_counter += 1;
}


}


Find me at: |Stormvisions| Twitter|
Re: Help Burt Learn Lite-C [Re: bupaje] #166635
11/09/07 11:53
11/09/07 11:53
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
As I'm only used to c-script this may be false, but I would move the PANEL* pDisplay out of the function and instead just set the flag of that panel to visible inside the function:
Code:

PANEL* pDisplay =
{
digits (35, 10, "Global Wind Speed: = %0.f", "Arial#16b", 1, vGlobal_Wind_Speed);
digits (35, 30, "Local Wind 1: = %0.f", "Arial#16b", 1, vLocal_Wind_1);
digits (35, 70, "Object 1: = %s", "Arial#16b", 1, sMessage);
}

function display_results()
{
set(pDisplay,VISIBLE);
}



Re: Help Burt Learn Lite-C [Re: Xarthor] #166636
11/09/07 16:39
11/09/07 16:39
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
Due to time constraints, product age, developmental history, etc. I haven't yet made a switch to Lite-C.


*Use the [ code ] [ /code ] tags to maintain formatting in code.
Code:

STRING* sMessage; // pointer points to NULL or garbage
sMessage = "Windy!"; // Wrong? Must allocate mem, etc.
sMessage = str_create("Windy!"); // Right?



Re: Help Burt Learn Lite-C [Re: testDummy] #166637
11/09/07 18:09
11/09/07 18:09
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. Still no good and there is somethings I'm not getting so please bear with me.

1. I still get a [null] for sMessage when I try to print. I'm guessing I misunderstand. I want to declare a string variable called sMessage, assign it a value in a function and return that to the print routine. Not sure where am going wrong.

2. Want to understand how to structure the program. I wanted to put the print routine and so on in seperate functions so as to break the program into discrete modules so I can better understand, then in main() simply call each module/function in order. This is how I remember it from basic anyway.
Code:

declare variables

functions

main routine
start
initialize
function1()
function2()
function3()
output
end


Once I can visualize the way to structure and sort out the pointers and memory stuff I didn't formerly have to deal with, think I'll be ok. Thanks for any help. Sorry for the noob questions - I'm not usually such a blockhead.


Code:
 
#include <acknex.h>
#include <default.c>

var vGlobal_Wind_Speed;
var vLocal_Wind_1;
var vObj1=1;

STRING* sMessage;
sMessage = str_create("Windy!");


function global_wind()
{
// generate global wind values

vGlobal_Wind_Speed = 50;

}

function local_wind()
{
//get global wind and adjust by local conditions

vLocal_Wind_1 = (vGlobal_Wind_Speed / 2);

}

PANEL* pDisplay =
{
digits (35, 10, "Global Wind Speed: = %0.f", "Arial#16b", 1, vGlobal_Wind_Speed);
digits (35, 30, "Local Wind 1: = %0.f", "Arial#16b", 1, vLocal_Wind_1);
digits (35, 70, "Object 1: = %s", "Arial#16b", 1, sMessage);
}

function display_results()
{
set(pDisplay,VISIBLE);
}

function main()
{
var temp_counter=0;

// initialize display
video_mode = 6;
screen_color.blue = 150;


// while wind engine is enabled
while (temp_counter<1)
{

global_wind();
local_wind();
display_results();
temp_counter += 1;
}

}




Re: Help Burt Learn Lite-C [Re: bupaje] #166638
11/09/07 20:12
11/09/07 20:12
Joined: Jul 2004
Posts: 1,205
Greece
LarryLaffer Offline
Serious User
LarryLaffer  Offline
Serious User

Joined: Jul 2004
Posts: 1,205
Greece
Hello bupaje,

In your last post, replace this:

Code:

STRING* sMessage;
sMessage = str_create("Windy!");



with this:

Code:

STRING* sMessage = "Windy!";



to get it working..

you see, when you type things outside of any function, all you are allowed to do is declare global variables, strings and such... so str_create("Windy!"); is not allowed since str_create is a name of a function, and you can only call other functions if you are in a function yourself (like in main() ).



You can also make the example you had in your first post working, if you replace this:

Code:

function local_wind()
{
// Generate Local Wind Values

//get global wind and adjust by local conditions

vLocal_Wind_1 = (vGlobal_Wind_Speed / 2);
sMessage = "Windy!";
return sMessage;
}



with this:

Code:

function local_wind()
{
// Generate Local Wind Values

//get global wind and adjust by local conditions

vLocal_Wind_1 = (vGlobal_Wind_Speed / 2);
str_cpy(sMessage,"Windy!");
}



You cannot edit strings, like you do with variables using '=', so you'll have to use the function str_cpy instead. There's also no need to 'return' anything since you've made sMessage a global string.



Quote:


2. Want to understand how to structure the program. I wanted to put the print routine and so on in seperate functions so as to break the program into discrete modules so I can better understand, then in main() simply call each module/function in order. This is how I remember it from basic anyway.





My advice is that you forget everything you've learnt in basic, and start with a fresh mind by studying the Lite-C tutorial. c64 basic was a batch language, meaning there were no functions or anything so of course your program structure would be different. what you describe looks more like qbasic or turbo basic which was procedural, but still more dated than lite-c in lots of areas.

You'll learn program structure by doing the tutorial and mimicking other examples, but in general c-script/lite-c programs tend to not use the main() function as much because of the Scheduler List feature and the use of wait(1), so you won't have to worry too much about creating while loops inside main() and trying to display an output at the end of it


Best of luck in this,
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] #166639
11/09/07 20:35
11/09/07 20:35
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 Aris. Your are right, I started with QBasic and QuickBasic. Even Visual Basic was simpler to understand since it was possible to create the interface based on how it would be used and think of the distinct events like button clicks, then sending data to a self contained textbox, then to a self contained database interface etc. For some reason anything 'c-like' always gives me a headache. I like putting things in little self-contained boxes which makes it easier to understand complexity for me. I thought if I could relate what little I do know to Lite-C I might be able to ease the birthing process. I'll go through the tutorials again.

Looking forward to AUM's coverage of Lite-C in a step by step "let's build a full small app today" approach rather than bits and pieces which, even though I follow the tiny example, doesn't give me the whole picture.


Find me at: |Stormvisions| Twitter|
Re: Help Burt Learn Lite-C [Re: bupaje] #166640
11/11/07 07:22
11/11/07 07:22
Joined: Aug 2002
Posts: 2,692
California, USA
bupaje Offline OP
Expert
bupaje  Offline OP
Expert

Joined: Aug 2002
Posts: 2,692
California, USA
Ok. Moving along, I wonder if anyone can give me a pointer on how to ease in and ease out wind speed values. For example I can set the wind speed to climb from 100 to 150 and it mechanically goes up. With random I can add little variations but not the smoothness of wind fading out.

Example code would be cool but a pointer to an example, some pseudo code or even a noob friendly suggestion of what I may want to investigate to approach this would be appreciated.

Again, nothing urgent here, just me picking at stuff but at least a few things are making more sense now.


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

Joined: Jul 2004
Posts: 1,205
Greece
I guess that what you want to look into is the wait() function. If you say you've made wind speed to mechanically climb up, then you've already figured out how to increment the wind value in a while loop

Code:

wind=100;
while (wind<150)
{
wind+=1;
}



but since you don't get to see every iteration of the while loop slowly, wind goes instantly from 100 to 150 in the screen. If you have the program wait for one tenth of a second though after every iteration, the number will gradually go up as u want it

Code:

wind=100;
while (wind<150)
{
wind+=1;
wait(-0.1);
}




Copy paste and run the program below and try to figure out how everything works:

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 100
#define HIGH_WIND 150

#define TENTH_OF_SECOND 0.1


function main()
{
// initialize display
video_mode = 6;
screen_color.blue = 150;

while (1)
{
for (vGlobal_Wind_Speed=LOW_WIND; vGlobal_Wind_Speed<HIGH_WIND; vGlobal_Wind_Speed++)
wait(-TENTH_OF_SECOND);
str_cpy(sMessage,"Reached High Wind");


for (vGlobal_Wind_Speed=HIGH_WIND; vGlobal_Wind_Speed>LOW_WIND; vGlobal_Wind_Speed--)
wait(-TENTH_OF_SECOND);
str_cpy(sMessage,"Reached Low Wind");
}

}



Some new things I've included:

While(1): This while loop will go on forever, because its expression (1) is taken as being always true. You could have also written another always true statement, like (10>5) for example, but while(1) is more customary.

#define: Some variables, i declared with #define instead of var, and typed them in all caps. These are numbers that aren't really variable, but always stay the same throughout the whole program, so it's better coding to use define for all those. The same way, it would be preferred to use define to declare pi, as #define PI 3.14 than use var pi=3.14, although it would have worked all the same. I could have also used the numbers 100 and 150 themselves and not use defines or vars at all, but avoid hardcoding numbers as much as you can. If you decide later that high wind is 170 instead of 150, but you've already used the number 150 many times in your program, it would be harder to replace them all one by one.


for(...): For loops are cleaner than while loops and sometimes preferred, in cases such as yours. The above could have been written with while loops, but i would have used more lines for it. The shorter you make your program, the quicker you, some one else and the compiler will read it

good luck,
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] #166642
11/11/07 18:17
11/11/07 18:17
Joined: Aug 2002
Posts: 2,692
California, USA
bupaje Offline OP
Expert
bupaje  Offline OP
Expert

Joined: Aug 2002
Posts: 2,692
California, USA
Aris, thanks for the very detailed and helpful response. I was confused about defines yesterday and now see they are constants. I thought they were like VB enums - is there an equivalent in Lite-C by the way? A way to group related variables or defines as eventually I was thinking I'd like to incorporate a scale like the Beaufort Scale http://en.wikipedia.org/wiki/Beaufort_scale

In a related question is it possible to group several strings to be able to access them via dot notation? I was trying to put all the "wind!" messages in a struct but guess I misunderstand its purpose.


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

Senior Expert
Orange Brat  Offline

Senior Expert
O

Joined: Aug 2000
Posts: 7,490
@bupaje: I'll post or send you my old wind script I mentioned in PM when I get home in a few hours. My Master List link is dead because of some peculiar deleting of older (or inactive?) threads. This has happened with a few of my ancient threads, but the c-script file is on my drive.

I don't have time to convert to Lite-C (I'm still learning it myself), but perhaps you or anyone else requiring a more detailed and feature rich wind script can convert it or make it more efficient at least.


My User Contributions master list - my initial post links are down but scroll down page to find list to active links
Page 1 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