Gamestudio Links
Zorro Links
Newest Posts
No errors in the command line
by JMMAC. 05/06/26 16:20
U4GM Where I Found Water Filters for Avian Alarm
by Hartmann846. 05/06/26 08:52
U4GM Why Black Ops 7 Campaign Feels So Different
by Hartmann846. 05/06/26 08:51
Purchase A8 full licence version
by jcl. 05/05/26 11:20
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (TipmyPip, Quad), 5,935 guests, and 13 spiders.
Key: Admin, Global Mod, Mod
Newest Members
salisy, Hartmann846, dangyc, ukgamer, valino
19213 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Handy defines [Re: Widi] #312074
02/23/10 03:54
02/23/10 03:54
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

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:
Code:
#define ternary(x, y, z) if(x) y; else z


Example:
Code:
// 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: JibbSmart] #316378
03/23/10 17:05
03/23/10 17:05
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
how come this works :
#define halt(x) while(x) wait(1)

i had no idea.. while 1 wait (1) but while (5) wait 1.. what this does?

Re: Handy defines [Re: MMike] #316381
03/23/10 17:36
03/23/10 17:36
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
Because 5 is != 0 it should do the same

Re: Handy defines [Re: FBL] #316420
03/23/10 23:36
03/23/10 23:36
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
but the concept behind the while x is what, while it whiles 5 it will decrease to 0 , to you get out of the loop?

Re: Handy defines [Re: MMike] #316422
03/24/10 00:20
03/24/10 00:20
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
while(5) should loop forever, unless an explicit 'break/return' statement is called.

0 is treated as false, and non-zero is treated as true.

Re: Handy defines [Re: DJBMASTER] #316567
03/25/10 00:13
03/25/10 00:13
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
@MMike: I believe the idea is for situations like this:
Code:
halt(!player);


=
Code:
while(!player)wait(1);

-- 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 Offline
Serious User
Redeemer  Offline
Serious User

Joined: Dec 2008
Posts: 1,660
North America
When you pass a conditional statement like this:
Code:
player != null


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:
Code:
while( player != null )


And the player IS null, then what the code actually means to the computer is:
Code:
while( 0 )


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:
Code:
while( 1 )


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:
Code:
temp = (temp==0);


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:
Code:
if( temp == 0 ) { temp = 1; return; }
if( temp == 1 ) { temp = 0; return; }




Eats commas for breakfast.

Play Barony: Cursed Edition!
Re: Handy defines [Re: Redeemer] #317386
03/31/10 07:59
03/31/10 07:59
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline OP
Expert
Joozey  Offline OP
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
temp = !temp is faster tongue


Click and join the 3dgs irc community!
Room: #3dgs
Re: Handy defines [Re: Joozey] #317595
04/01/10 12:55
04/01/10 12:55
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
thats witchcraft

Re: Handy defines [Re: MMike] #318418
04/07/10 15:08
04/07/10 15:08
Joined: Oct 2007
Posts: 306
Austria
A
Alan Offline
Senior Member
Alan  Offline
Senior Member
A

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:

Code:
// 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

Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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