PDA

View Full Version : Minor COG discoveries



Emon
11-15-2003, 11:42 AM
I was fooling around this morning and found out some interesting things.

1. The ^ operator, exclusive OR (XOR). Compares two values, and returns a value that has its bits set if one or the other value has its corresponding bits set, but not both.


1 ^ 1 == 0
1 ^ 0 == 1
0 ^ 1 == 1
0 ^ 0 == 0


Can be used as bitwise or logical, e.g. if(var1 ^ var2).

It can be useful for swapping two variables, other than a string, in COG.


X = X ^ Y;
Y = Y ^ X;
X = X ^ Y;



2. The ! operator, logical NOT. This may not be new, but I can't remember seeing it in any LEC or custom COGs, but I haven't looked in a while. if(!(var1 == var2)) is the same as if(var1 != var2). It's not really useful in COG since there aren't any boolean data types (I tried bool and boolean with values of true/false and 0/1 to no avail), and I'm pretty sure COG doesn't think of 0 as false and 1 as true, so if(var1) won't work, neither will if(!(var1).

3. Crude return functions with the user messages. In real languages, you can make a function that will accept parameters, and return a new value, so you can go var1 = pow(5, 6); and var1 will become 5 to the 6th power, which was figured out in the pow function.



symbols
...
message user0 // Power "return function", pass two numbers with SendMessageEx and receive the first parameter to the second.
...
printInt(SendMessageEx(GetSelfCog(), user0, X, Y, 0, 0));
...

user0: // Power "return function".
temp = GetParam(0);
for(I = 0; I < GetParam(1) - 1; I = I + 1)
temp = temp * GetParam(0);
ReturnEx(temp);



None of this is really useful, but I thought someone might find it interesting.

------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.

EH_AceCSF
11-15-2003, 12:11 PM
Hmm if we can use pow(A, B); then we can make many intresting things..

------------------
The miners of Kiith Somtaaw sacificed much, and risked all. For their efforts they were brought into the inner most circle of Hiigaren power. Naabal, S'jet, and Sobanii bowed before them. And from that day to this, Somtaaw's children have been known to one and all as Beastslayers..

SaberMaster
11-15-2003, 12:19 PM
XOR is definitely a nice discovery, but the other two should be well known.

------------------
Author of the JK DataMaster (http://www.geocities.com/sabersdomain/files.html), Parsec (http://www.geocities.com/sabersdomain/files.html), Scribe (http://www.geocities.com/sabersdomain/files.html), and the EditPlus Cog Files (http://www.geocities.com/sabersdomain/files.html).

Emon
11-15-2003, 12:24 PM
I also tried the ~ operator, which is inversion or Ones Complement, and it doesn't work. I also messed around with C-style arrays, which only crashed JK. I also tried concatenation with string variables, but that doesn't want to work, either. And I tried accessing individual string characters like you might in C/C++ (for C-style or STL strings), with the [] subscript operator, e.g. print(myString[5]); didn't print out the fourth character in the string.

Oh, heh, I also tried pointers, which I was certain couldn't be there, but I tried anyway, didn't work, heh.

------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.

[This message has been edited by Emon (edited November 15, 2003).]

[This message has been edited by Emon (edited November 15, 2003).]

gbk
11-15-2003, 03:23 PM
The first one is . . . interesting . . . the others are old news.

------------------
Fight (http://12.220.251.111/cgi-bin/addies.pl) the (http://12.220.251.111/ol) future (http://12.220.251.111/ol/cogpad/cogpad.html).

Emon
11-15-2003, 10:14 PM
Alright; I haven't done this in years, I wasn't sure.

------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.

EH_AceCSF
11-16-2003, 06:57 AM
hm i got question: How to print string and int in one line?
Like Print("number is.."[int]); or? Possible?

------------------
The miners of Kiith Somtaaw sacificed much, and risked all. For their efforts they were brought into the inner most circle of Hiigaren power. Naabal, S'jet, and Sobanii bowed before them. And from that day to this, Somtaaw's children have been known to one and all as Beastslayers..

SaberMaster
11-16-2003, 10:23 AM
jkStringConcatFormattedInt();

------------------
Author of the JK DataMaster (http://www.geocities.com/sabersdomain/files.html), Parsec (http://www.geocities.com/sabersdomain/files.html), Scribe (http://www.geocities.com/sabersdomain/files.html), and the EditPlus Cog Files (http://www.geocities.com/sabersdomain/files.html).

[SF]pjb
11-17-2003, 04:07 PM
ok...... for the people among us that dont speek the english good what exactly dose ^ do again??


p.s. it must have been fun in the old days finding new operatiors, and fantastic discoverys in cog verbs.. DANG why wasent i born five years earlyer?

------------------
I am pjb.
Another post......
another moment of my life wasted.....
at least i made a level.
PJB's JK page's (http://www.geocities.com/SF_PJB1)

-the PJB jedi rule book-
rule one, "never trust a bartender with bad grammar"-kyle katarn in JO

Rule Two, "Gravity is a crule misstress" -kyle katarn in MotS, and the alternatior MK I in AJTD

rule three, "asprines good, but it hasent got the kick of morphine. and its not gonna stop the hurting in my arm, the ones thats on the otherside of the room i mean" -the alternatior

Emon
11-17-2003, 06:05 PM
Lookup bitwise operators on Google, you should find something on XOR.

------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.