Comments are closed

cJass on the Google Code.
Our BugTracker (recommend to post bugreports and features request there).
Beta tester notes.

all times are GMT +03:00
Latest posts

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [19] 20 21 22 23 24 25 26 27

posted at 01/10/09 09:37

Is it possible to get macros to compile in a fix order or to do multiple passes? I'm trying to have something use a macro as if it were a function::
define GetHashCode(T) = GetHashCode_##T
define Real2Hash(v) = StringHash(R2S(v));
define InitHasher(T,HashMethod) =
int GetHashCode(T)(T value)
return HashMethod(value);
InitHasher(real,Real2Hash) causes it to freak out.
This is not possible directly, but there is one way for now:
<div class="code"><b>define</b>
&nbsp;&nbsp;GetHashCode(T) = GetHashCode_##T
&nbsp;&nbsp;Real2Hash(v) = StringHash(R2S(v));
&nbsp;&nbsp;InitHasher(T,HashMethod) =
&nbsp;&nbsp;&nbsp;&nbsp;int GetHashCode(T)(T value)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return HashMethod;

posted at 01/10/09 04:36
Dark Dragon

just wanted to report the bug i found!
define {
integer = integ ## er
integer(x) = GetHandleId(x)
will compile and work correctly if i put that in map directly! but if i use external file and #guard it will display some strange compile errors and characters...
ofc take ur time to test this tomorrow :)
Strange. This code works just fine:
<div class="code">#include "test.j"
integer test (handle x) {
&nbsp;&nbsp;return integer(x)
whereas test.j contains
<div class="code">#guard TEST_J
define {
&nbsp;&nbsp;integer = integ ## er
&nbsp;&nbsp;integer(x) = GetHandleId(x)

posted at 01/10/09 03:48

Re: Mailing you.
Yeah.. I'd need the makers permission to do that and such. But the code that is erroring.. if I isolate the vJass library where it is erroring at it compiles perfectly. All I can assume about the map itself is because it uses WEU and such that it is messed up incredibly for any sort of mod like this to ever work perfectly on.
Thank you regardless for your help.. looks like I'm just going to not work on trying to find a bug for the guy.
Strange. I've just added this "Map Meta Data Library" to my test map and it compiles just fine. If it's not modified in any way, then it shouldn't cause errors. If it IS modified, then I should have a look at it, or I can do nothing to help you.

posted at 01/10/09 03:16
Dark Dragon

Good night and thanks for answering the questions!
Thanks, now I hope it's over for real.
I'll wait for your map tomorrow.

posted at 01/10/09 03:14

", id, i)\n exitwhen true\n endif\n set i = i + 1\n endloop\n endif\n return i\n endfunction\n\n ///Computes a weak hash value, hopefully secure enough for our purposes\n private function poor_hash takes string s, integer seed returns integer\n local integer n = StringLength(s)\n local integer m = n + seed\n local integer i = 0\n loop\n exitwhen i >= n\n set m = m * 41 + C2I(SubString(s, i, i+1))\n set i = i + 1\n endloop\n return m\n endfunction\n\n ///Stores previously sent messages for tamper detection purposes\n private struct QueueNode\n readonly real timeout\n readonly string msg\n readonly integer checksum\n readonly string key\n public QueueNode next = 0\n public static method create takes integer id, string msg returns QueueNode\n local QueueNode this = QueueNode.allocate()\n set .timeout = time() + 7.0 + GetRandomReal(0, 2+0.1*GetPlayerId(GetLocalPlayer()))\n set .msg = msg\n set .checksum = poor_hash(.msg, id)\n set .key = I2S(id)\n return this\n endmethod\n private method onDestroy takes nothing returns nothing\n call FlushStoredInteger(gc, M_KEY_VAL+.key, .msg)\n call FlushStoredInteger(gc, M_KEY_CHK+.key, .key)\n set .msg = null\n set .key = null\n set .next = 0\n endmethod\n public method send takes nothing returns nothing\n call StoreInteger(gc, M_KEY_VAL+.key, .msg, .checksum)\n call StoreInteger(gc, M_KEY_CHK+.key, .key, .checksum)\n call SyncStoredInteger(gc, M_KEY_VAL+.key, .msg)\n call SyncStoredInteger(gc, M_KEY_CHK+.key, .key)\n endmethod\n endstruct\n \n ///Returns true for a fixed size uniform random subset of players in the game\n private function isEmitter takes nothing returns boolean\n local integer i = 0\n local integer n = 0\n local integer r\n local int
I am appearing to get "string too long errors" and this occured only after my new update. It also whined at me about a COMMENT.
Send me your test map to and I'll see what's the matter tomorrow. I can say nothing from the mess you provided, I need original code =)

posted at 01/10/09 03:11

Sigh errors that never have happened before.
n endglobals\n\n ///////////////////////////////////////////////////////////////\n /// Private variables and constants\n ///////////////////////////////////////////////////////////////\n globals\n private constant boolean SHOW_DEBUG_MESSAGES = true\n \n private constant string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-+=\\!@#%^&*()/?>.<,
The last "B" there is highlighted, and it says incorrect literal. I can personally assure you that it is NOT incorrect because it has compiled fine before.
The actual line it appears to be erroring at is:
private constant string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-+= \\!@#$%^&*()/?>.<,;:'\"{}[]|`~"
Is there something wrong with endline manipulation and ;?
Can you provide more code please? Just your <div class="code">
private constant string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-+= \\!@#$%^&*()/?>.<,;:'\"{}[]|`~"</div> works well.

posted at 01/10/09 03:10
Van Damm

Good night everyone, support session is over for today xD

posted at 01/10/09 03:00
Dark Dragon

ohh sry for spam but i posted just at time where u answerd Mooglefrooglian's question...
so about #guard! i am just not sure what name should it be... i mean SOMENAME should be file name? so like this:
#guard cj_antibj_base.j
or smth else?
as well FUNCNAME how exactly should i use it?
i mean is it string or is it just macro name?
i mean if u could write an example xD it would be great!
SOMENAME is any name you like, elegible to be a variable name (alphanumeric symbols or _ sign).
All predefined macros return values without quotes so you can easily do smth like
<div class="code">void fx () {
&nbsp;&nbsp;int i_##FUNCNAME = 0
which will become
<div class="code">
function fx takes nothing returns nothing
&nbsp;&nbsp;local integer i_fx = 0
Anyways, to convert the predefined macro to string, there are two ways:
1. <span class="code">define stringize(x) = `x`</span> and use it with predefined macros like <span class="code">stringize(FUNCNAME)</span>
2. <div class="code">#include "cj_print.j"
void test() {
<i>// you can use any other function from cj_print
// or even sprintf if you want to get a string</i>

posted at 01/10/09 02:57

Thanks again for everything.. interestingly, I did find a way to avoid hooking globally initalized CreateTiemrs(). I merely did:
define CreateTimer = Create ## Timer
Randomly in my little debug trigger, and then at the top of the map script, I put:
setdef CreateTimer = CreateTimer_Hook
Which makes it so I hook only non globalised CreateTimer() calls.. I would like to have the globally initted ones as well, buuut.
Also, odd bug:
function Trip_AbilCode takes nothing returns integer
return 'A05B'
Errors for me and according to my compiler:
function Trip_AbilCode takes nothing returns integer
And errors because it has no return and such.
Is this cJass or vJass erroring? I never had this problem before I installed cJass, so..
Sorry, that's ADOLF's over-optimization. Please surround your return value with curly brackets for now (like this <span class="code">return ('A05B')</span>) it will work until ADOLF fixes the bug.

posted at 01/10/09 02:54
Dark Dragon

thanks VD i thought it worked that way but was not sure, so once again thanks :)

posted at 01/10/09 02:48

# + Added #error directive.
# + Added #guard directive.
# + Added FUNCNAME system define.
Can you go into further detail about what all of these will do? FUNCNAME assumably will tell the name of the function? But what about the rest?
<span class="code">#error "text"</span> is for usage with conditional compilation like
<div class="code">define TEST = 1
#if TEST
&nbsp;&nbsp;#error "Not implemented"
It will stop compilation and show the message.
<span class="code">#guard SOMENAME</span> is to be written at the beginning of external files, which you include. So then if you include them more than once, the parser will detect that and include only once. So this is our version of include guard or MSVC's #pragma once.
And you're correct about the FUNCNAME

posted at 01/10/09 02:37
Dark Dragon

ahh sry xD
i actually never understanded how this setdef and all that works...
defines are replaced before and after the line: define smth = smth_else
now smth will become smth_else
however setdef means that define will now be changed but from where to where :S
undef as well what does that mean that it will be removed or smth? but i cant fully understand from which point and what will happen after its removed...
so here example:
nothing smth() {}
define smth = blah
setdef smth = smth_else
integer smth = 0
undef smth
real smth = 0.0
nothing smth() {integer i = smth_else; blah()}
is that correct or did i understand it wrong?
thanks :)
If you <span class="code">define smth = smthelse</span> at any point, it will affect the whole map code (if the define is not private).
Then the map code is parsed from the beginning: all occurrences of <span class="code">smth</span> are replaced to <span class="code">smthelse</span> until the parser meets <span class="code">setdef</span> directive (eg <span class="code">setdef smth = smthother</span>).
After this point, all occurrences of <span class="code">smth</span> will be replaced to <span class="code">smthother</span> until other <span class="code">setdef</span> or <span class="code">undef</span> occurs.
If then the parser meets <span class="code">undef smth</span>, after this directive all occurrences of <span class="code">smth</span> will be left as they are until there is other <span class="code">setdef</span> in the future =)
So your code
<div class="code">void smth() {}
define smth = blah
setdef smth = smth_else
int smth = 0
undef smth
real smth = 0.</div>
will be translated to:
<div class="code">nothing blah() {}
integer smth_else = 0
real snth = 0.0</div>

posted at 01/10/09 02:26
Dark Dragon

very nice update, gj guys!
hope to see 1.4 as well ;)
about while loop, well if you say so then i guess ill define it that other way.
about what u asked i think u can do this:
define CreateTimer = Create ## Timer
setdef CreateTimer = CreateTimer_hook
this code should be at the top but after main GUI globals
Your code won't work, I've described why in my reply to Mooglefrooglian's post. Please read it first =)

posted at 01/10/09 01:40

Thanks a lot. A custom common.j never occured to me. I'd love to see what ADOLF comes up with.
Have a good one.

posted at 01/10/09 00:58

Hi, I posted the problem earlier, but you seem to have misunderstood me.
Because some of the variables are GUI, and initialised in the Varible Editor, they are moved to the top of the map script. It is IMPOSSIBLE to put a function above those, and as such I can't hook a function like CreateTimer(). I would like to know if there is a way I can get it to avoid hooking globals that are initted, or else find a way to get a function above those globals.
THank you for the response though. My original question was:"Small problem. Defines affect the globals in the map header. Therefore I am unable to hook CreateTimer() and such because it is defined with GUI variables.
Any fix? Or did I not read syntax correctly?"
Sorry, I misunderstood you. You cannot place any functions before the globals block, so for now you have only one way of doing what you want - import custom common.j or blizzard.j into your map and write your hook function there.
The other way for now is to create a define, that overrides your hooked function to return null and then initialize the variables manually, but I think this is now exactly what you want.
Your request is rather non-typical and ADOLF said that he'll think on the way of making this possible.

posted at 30/09/09 22:43
Dark Dragon

yeah i once defined it like:
define while (expr) = whilenot not (expr)
but Van Damm told me it was better the other way, it was coz i had to type arguments like this:
while (<my_expr>)
i guess now thats fixed... :)
Yeah, that was long ago before we fixed define arguments. Now it's better to do like ADOLF said.

posted at 30/09/09 22:28

about while)
for safe I recommend this:
<span class="code">define while (expr) = whilenot !(expr)</span>

posted at 30/09/09 21:30
Dark Dragon

this is the way to do it correctly:

define UnitData(u) = unitdata(GetUnitUserData(u))
struct unitdata extends array
integer ID = xxx
integer Type = xxx
nothing Test () {
unitdata ud = UnitData(GetTriggerUnit())

if define has arguments it must be called with arguments so you cant have with same name struct and define.
btw my stile is to always have types with lower-case.

posted at 30/09/09 17:20

Sorry, my examples arr too bad.
a new example:
define <UnitData>(u) = UnitData(GetUnitUserData(u))
struct UnitData extends array
integer ID = xxx
integer Type = xxx
nothing Test () {
UnitData = UnitData(GetTriggerUnit())
OK, now I get what you're trying to do. <s>For now there is a small limitation with overloaded defines with no arguments, but it will be fixed in the future versions.</s>
Now (in you can do so:
<div class="code">define {
&nbsp;&nbsp;UnitData = Unit##Data
&nbsp;&nbsp;UnitData(u) = Unit##Data(GetUnitUserData(u))
struct UnitData extends array {
&nbsp;inte&nbsp;ger ID = xxx
&nbsp;inte&nbsp;ger Type = xxx
nothing Test () {
&nbsp;&nbsp;UnitData = UnitData(GetTriggerUnit())
}</div>and it will work as expected.

posted at 30/09/09 16:17

Sometimes i want to
define <Test> = Test
define <Test>(x) = Test(x)
struct Test extends array
// xxxxxxxxx
// xxxxxxxxx
nothing CantWork () {
Test a = Test(1)
Test b = Test.Create()
What should i do ?
I see no reason in your defines. Can you explain, what you're trying to accomplish?

posted at 30/09/09 16:14
Dark Dragon

yeah when we are talking about blizzard.j!
is it possible for adolf to recode blizzard.j by fixing blizzards own bad code and then insted of using blizzard.j from .mpq he injects his own code directly in the map.
that would really be great but not neccessary.
about my wish list, ill add few more which i forgot about last time.

  1. default arguments
  2. no "function" keyword but "&" char maybe
  3. private: and public:
  4. function/method overloading
  5. "for" loop
  6. [] instead of "array" keyword
  7. static variables inside funcs/methodes

numbers mean priority to me :)
this 7 are important to me and i hope that ADOLF will like them as well. so maybe in 1.5 ill be able to see this requests but i know i cant wish to much since this all might be hard to add, i mean i dont know asm so... :)
as well nice that this bug with while loop is fixed in!

posted at 30/09/09 07:52

Small problem. Defines affect the globals in the map header. Therefore I am unable to hook CreateTimer() and such because it is defined with GUI variables.
Any fix? Or did I not read syntax correctly?
You can do it as soon as you also hook the one, used in GUI. It's <span class="code">CreateTimerBJ()</span>

posted at 30/09/09 04:05
Dark Dragon

k anyway thanks and i hope it gets fixed :)

posted at 30/09/09 03:52
Dark Dragon

found a crash!
while (this.qn-- > 0) { this.qi[this.qn] = null;[this.qn] = null }
qn = integer
qi = questitem array [32]
in = string array [32]
as well while is defined like you said
define while = whilenot not
<s>I'll now look into this</s>
Dunno what's the matter, but this is because of postfix increment. I'll tell ADOLF and this will be fixed.
<span class="code">whilenot !(this.qn-- > 0) { this.qi[this.qn] = null;[this.qn] = null }</span>
works. hmm... where is my debugger?)
<span class="code">whilenot not(this.qn-- > 0) { this.qi[this.qn] = null;[this.qn] = null }</span>
crash! omg
EDIT: fixed in =)

posted at 30/09/09 01:01
Dark Dragon

k thanks!
i never actually learned (C) i started with (C++) so i dont know what the difference is xD
glade to hear enums can be treated as types, for now i guess ill have to do this:
enum {smth, smth_else...}; define name = integer
for now that will work :)
about overloading defines, yes i knew that if i call it with () it will work but i had already made it in whole script without () so i only wanted to know will ADOLF remove this limitation in feature :)
once again thanks for all your answers and help!
~Dark Dragon

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [19] 20 21 22 23 24 25 26 27

[back to top]