|
2 registered members (TipmyPip, Quad),
5,935
guests, and 13
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Handy defines
[Re: Widi]
#312074
02/23/10 03:54
02/23/10 03:54
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
I really wish Lite-C had ternary operations like real C. This isn't quite equivalent, but it'll do, and I feel it can help clean things up:
#define ternary(x, y, z) if(x) y; else z
Example:
// basically the same as x = maxv(a, b); but I couldn't think of a simpler example
ternary(a > b, x = a, x = b);
Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: Handy defines
[Re: DJBMASTER]
#316567
03/25/10 00:13
03/25/10 00:13
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
@MMike: I believe the idea is for situations like this: = -- that is, wait until the player exists. It's "halt until the condition is true", not for setting timers or the like. Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: Handy defines
[Re: JibbSmart]
#316825
03/26/10 21:58
03/26/10 21:58
|
Joined: Dec 2008
Posts: 1,660 North America
Redeemer
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,660
North America
|
When you pass a conditional statement like this: You are actually calling a special kind of function that checks the validity of the statement and returns either 0, meaning "false" or a non zero number like 1, that means "true". So if you write: And the player IS null, then what the code actually means to the computer is: Of course, this will not be executed. The computer will skip on to the next set of instructions following the while loop. Likewise, if the player ISN'T null, then what the code means to the computer is: And the computer will execute the code within the while loop. Once it has finished executing the code, it will re-evaluate the conditional statement made in the while() instruction, and if the statement returns a 1 again, then it runs through the code again. Conditional statements can thus be used in more than just "if" "do" and "while" instructions: If temp is 0, then the conditional statement will return a 1, and temp will be set to 1. If temp isn't 0, then the conditional statement will return a 0, and temp will be set to 0. This way you can toggle a variable on and off without writing drawn out code like this:
if( temp == 0 ) { temp = 1; return; }
if( temp == 1 ) { temp = 0; return; }
|
|
|
Re: Handy defines
[Re: Joozey]
#317595
04/01/10 12:55
04/01/10 12:55
|
Joined: Jul 2004
Posts: 1,710
MMike
Serious User
|
Serious User
Joined: Jul 2004
Posts: 1,710
|
|
|
|
Re: Handy defines
[Re: MMike]
#318418
04/07/10 15:08
04/07/10 15:08
|
Joined: Oct 2007
Posts: 306 Austria
Alan
Senior Member
|
Senior Member
Joined: Oct 2007
Posts: 306
Austria
|
Hi, something I tend to use a lot for debugging is a simple log file. I've written a .c-file which handles all important functions:
// LOGGING.c
//============================================================================
// Contains all basic functionality for creating a LOG file for debugging.
//============================================================================
var file_handle;
void log_new_line() // just creates a new line.
{
file_asc_write(file_handle, 10);
file_asc_write(file_handle, 13);
}
void quotes() // if you ever happen to absolutely NEED quotes ""
{
file_asc_write(file_handle, 34);
}
void log_write(STRING* content) // writes the "content" to the log. No new line.
{
file_str_write(file_handle, content);
}
void log_writeln(STRING* content) // writes the "content" to the log.
{ // followed by a "new line" command.
file_str_write(file_handle, content);
log_new_line();
log_new_line();
}
void log_number(var a) // writes a number to the log. No new line.
{
file_var_write(file_handle, a);
}
void open_log_file() // ATTENTION: you NEED to call this ONCE *before*
{ // you write something to the log file!!
file_handle = file_open_write("MY_LOG.txt");
}
It is fairly easy to use, the function names should be self-explanatory, just *remember* that you need to call "open_log_file()" once in your main-function before you add a line to it. Could be expanded, but it suits my needs. Strange detail: when writing a log file, doing "new_line()" once won't do anything. You'll need to call it *twice* to really get a new line. Don't know why, though. Greets, Alan
|
|
|
|