Simple wdl to C-script negation conditional

Posted By: Ericmor

Simple wdl to C-script negation conditional - 05/16/11 20:09

Hi people,
Having trouble to find a working example of negation conditional in the manual.
A flag conditional code is translated from wdl to lite-C the following way...

Code:
//c-script
if(my.flag1==1)
 {
  my.flag4=1;
  my.flag1=0;
 }



Is writen this way in Lite-C:

Code:
//lite-C
if is(my,FLAG1)
 {
  set(my,flag4);
  reset(my,FLAG1);
 }



Now, how i translate the following wdl code?

Code:
//C-script
var variable_test;

if(my.flag1==0)
{
variable_test=my.FLAG1;
}



I really couldnīt find this one. Sorry for the stupid question... any help is appreciated.
Thanks in advance.
Posted By: JibbSmart

Re: Simple wdl to C-script negation conditional - 05/16/11 20:19

Code:
var variable_test;
if (!is(my,FLAG1)) {
	variable_test = 0;
}


Jibb
Posted By: Ericmor

Re: Simple wdl to C-script negation conditional - 05/16/11 20:31

Thanks JulzMighty!
Iīve tried combinations with the "(!)", but it was crashing... now works, wonder what i did wrong.
Seems like i canīt declare a flag as a value to a variable anymore...oh well.
Thanks again.
Posted By: JibbSmart

Re: Simple wdl to C-script negation conditional - 05/16/11 20:52

No worries! Here's some more info if you need, of how flags work in Lite-C.

A var is 32-bits. A flag is only 1 bit (since it is either 1 or 0). So a var can contain 32 flags. Every entity has a "flags" var that contains their flags (and some flags in a "flags2" component).

If you want more general purpose flags (like FLAG1...FLAG8) you can store your own in other entity skills, if you know how to access them.

The bitwise operators are used to interact with individual bits in a variable, and as such can be used to interact with flags.

For example, set(my,INVISIBLE) is the same as:
Code:
my.flags |= INVISIBLE;

That means, set all the bits in flags to 1 that are already set in flags OR are set in INVISIBLE. INVISIBLE is all 0s except for a "1" in the right place for the INVISIBLE flag.

It's worth investigating further as you get more into Lite-C.

Jibb
Posted By: Ericmor

Re: Simple wdl to C-script negation conditional - 05/16/11 23:04

Thanks again!
I wasnīt sure if the |= operator would work in a conditional (iīm using set/reset/toggle for them)so i didnīt even tried - thanks for the manual page tip!
By the way, in the examples of this page...
Code:
z += 1; // add 1 to x


I think they should fix that, someone might not understand (like me)!
Posted By: JibbSmart

Re: Simple wdl to C-script negation conditional - 05/17/11 00:28

Ha! Yes, they should fix that. You should let them know in the "Blame The Manual" forum.

Jibb
© 2024 lite-C Forums