Wc3C.net

Wc3C.net (http://www.wc3c.net/forums.php)
-   Warcraft Editing Tools (http://www.wc3c.net/forumdisplay.php?f=13)
-   -   JassHelper 0.A.2.B - A vJass and Zinc 2 Jass compiler (http://www.wc3c.net/showthread.php?t=88142)

Vexorian 11-29-2006 10:07 PM

I don't really understand what you mean by "support dynamic arrays"

The rest are all bugs. Let me check
---
Edit: I just tested both examples and no syntax errors, are you using latest version? Maybe there's something else involved causing the issue.

BlinkBoy 11-30-2006 01:26 AM

You right, i forgot to update to the latest version, thanks alot.

Vexorian 11-30-2006 02:01 AM

so, what did you mean by the dynamic array support?

Vexorian 12-16-2006 02:11 PM

0.9.4 is up, a lot of new features:

methods


Collapse JASS:
struct Vector
    real x=0
    real y=0
    real z=0

    // sorry, no syntax for actual constructors, you can always make dummy ones though...
    static method create_from takes real x, real y, real z returns Vector
     local Vector n=Vector.create()
        set n.x=x
        set n.y=y
        set n.z=z
     return n
    endmethod

    method magnitude takes nothing returns real
        return SquareRoot( this.x*this.x + this.y*this.y + this.z*this.z)
    endmethod

    // this is necessary, it was easier to code but it also removes ambiguousness
    // and enforces to notice that it is a whole access and not just 'normal' var usage
    method plus takes Vector B returns nothing
        set this.x=this.x+B.x
        set this.y=this.y+B.y
        set this.z=this.z+B.z
    endmethod

    // yeah, static methods...
    static method addition takes Vector A, Vector B returns Vector
     local Vector C=Vector.create()
        set C.x=A.x+B.x
        set C.y=A.y+B.y
        set C.z=A.z+B.z
     return C
    endmethod

    // onDestroy is called when .destroy() is used
    method onDestroy takes nothing returns nothing
     local code c=(function Vector.err)

        call BJDebugMsg("Funny, the vector was destroyed")
    endmethod

endstruct

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing

 local Vector A=Vector.create_from(4.5,3.4,2.1)
    call BJDebugMsg(R2S(A.magnitude()))

    call Vector.destroy(A)
    call Vector.destroy(A) //double free is now prevented!

endfunction




Polymorphism (interfaces)

Collapse JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
 local expression e= sum.createFrom( sum.createFrom( value.createFrom(8),  sum.createFrom(value.createFrom(2),value.createFrom(-1)) ) , value.createFrom(12) )
 local sum e2
 local sum e3
 local integer i=1000

    call BJDebugMsg(I2S(e.evaluate()))
    call e.destroy()
    set e2=sum.createFrom(value.createFrom(1) ,  value.createFrom(1) )
    loop
        exitwhen i==0
        set e2.a = sum.createFrom( value.createFrom(1) , e2.a)
        set i=i-1
    endloop

call TriggerSleepAction(0.)
    call BJDebugMsg(I2S(e2.evaluate()))
    call BJDebugMsg(I2S(e2))
    call e2.destroy()



endfunction

interface expression
    method evaluate takes nothing returns integer
endinterface


struct value extends expression
    integer v=0

    static method createFrom takes integer v returns value
     local value o=value.create()
        set o.v=v
     return o
    endmethod

    method evaluate takes nothing returns integer
     local value x=this
        return this.v
    endmethod
endstruct


struct sum extends expression
    expression a = 0
    expression b = 0

    static method createFrom takes expression a, expression b returns sum
     local sum o= sum.create()
        set o.a=a
        set o.b=b
     return o
    endmethod



    method evaluate takes nothing returns integer
        return this.a.evaluate() + this.b.evaluate()
    endmethod

    method onDestroy takes nothing returns nothing
        if(this.a!=0) then
            call this.a.destroy()
        endif
        if(this.b!=0) then
            call this.b.destroy()
        endif
    endmethod

endstruct



Methods are not like normal functions:
- You can call methods from every position of the script without problems
- In exchange, it is not a good idea to have waits or GetTriggeringTrigger() inside methods.


An involuntary feature is that static methods that take nothing can actually be used as code values (function class.method) !


inject


Collapse JASS:

//! inject main
     call BJDebugMsg("Look! I just replaced the map's main function")

     //! dovjassinit
     // (always required, structs and libraries need some initializing)

//! endinject



//! inject config

    // injecting config really needs to setup players and stuff really well otherwise it crashes.

//! endinject

//These things were requested by IceFrog and I kind of liked the idea...



--

The grimoire pack and the documentation for 0.9.4 features might take some time.

---
BTW you 'can' use a single . inside methods so this or classname are implicit but I don't really like this.

For example, in the above sample it could be: set .x = .x + B.y

BlinkBoy 12-16-2006 04:23 PM

Quote:

Originally Posted by Vexorian
so, what did you mean by the dynamic array support?


Nah forget it, the problem was that in my old problem, I had to declare arrays iten by iten and not use a loop that can change Ā«making a dynamic array. I think I'll explain myself.

In other languages such as in Visual Basic, there are 2 types of arrays Static and Dynamic. Static Arrays in VB have a limited amount of spaces, example:\
Code:

Dim D(8) as Double
this means that the array will be limited to store 9 variables 0 to 8. In the other hand dynamic arrays were subjected to the system limits, so you declared them by not adding any value between the (). That was why I got confused.

Anyways a good suggestion would be multidimensional arrays, It would be better for administrating your information a jass syntax example could be:

Collapse JASS:
globals
        real array dim(2) MyArray
endglobals

function MyFunction takes real b, real c, real a, real index returns nothing
set real k = SquareRoot( (b*b) - (4*a*c))
set MyArray[index,1] = (k - b) / (2*a)
set MyArray[index,2] = ((-1)*k - b) / (2*a)
// I know that I can use an sruct for this, but it would be problematic if I would like to make my code more flexible
endfunction

I'm 100% sure you already know all this, but just as a reference, It would be nice if you could add that, maybe my example is not the best one to reffer to this, but i'm sure it is usefull.

Vexorian 12-16-2006 06:12 PM

I am still limited by JASS' own limitations, in JASS all arrays take 8192 , nd arrays could happen I am not sure if after coding all the . non-sense for structs I have the intenrion of going crazy on parsing [] variations o_O

wyrmlord 12-16-2006 06:34 PM

If you wanted to create a multi-dimensional array, you'd have to put a limit on how large each index could be. For instance, if you had a limit of 90 for each index in a two dimensional array, it would work. If you had a limit of 20 for each index, you could have a 3 dimensional array. There's no "real" way to do multi-dimensional arrays in JASS.

Also, the struct idea is giving me an idea on how to make a system to store/retrieve values that would be faster than gamecache. You have a node struct, like in a linked list. That node contains 3 variables, one is an integer, representing the 'key' you store a value under, one is whatever value is being stored (I'm going to like text macros), and the third is another node. To store a value, you give the function a key (meant to be the integer version of a handle). The function would then keep going to the next node over and over again until it either found that key (from a previous use) or an empty spot, where it would then create a new node and store the information there. The only thing is, I'm wondering if this would work and not bug.

BlinkBoy 12-17-2006 03:21 AM

Hmm, yap maybe 1 array is not complecent for multidimensional needs.

Btw to wyrmlord, that system wouldn't save much processing, since you still depend of the safecasting [example: H2I], which is the function that makes processing a bit longer.

wyrmlord 12-17-2006 03:28 AM

Actually, the way that my code works, I don't need to store it as an integer, I can store it using a handle or w/e actually. If you're interested in seeing the code just ask.

Suggestion for the program: Variable array support in structs.

BlinkBoy 12-17-2006 03:53 AM

Hey I know one, how about the old Select Case? is not as confusing as having many elseif.

Collapse JASS:
globals
        constant integer NullTeam = 3
endglobals

function GetPlayerTeamIDtakes player p returns integer
select case GetPlayerID(p) // takes a value

         case  this < 7
                 return 1
         case 7 < this and this < 13
                 return 2
         case else
                 return NullTeam
endselect
endfunction

// another form, a function that identifies a pair of numbers between 1 to 10

function IsPair takes integer i returns boolean
select case i

         case  2, 4, 6, 8, 10
                 return true
         case 1, 3, 5, 7, 9
                 return false
         case else
                 return false
endselect
endfunction

struct longitud
         real value 0
         string scale = "miles"
endstruct

//Now a practical one.
function ConvLongitud takes longitud l, string newscale takes returns nothing
if l.scale = "miles" then
    select case newscale
         case  "feet"
                 set l.scale = "feet"
                 set l.value = 5280 * l.value
         case "yards"
                 set l.scale = "yards"
                 set l.value = 1760 * l.value
         case "inches"
                 set l.scale = "inches"
                 set l.value = 63360 * l.value
    endselect
elseif l.scale = "feet" then
//.... and so on and so on.
endif
endfunction      

Anyways, could you show me the code?, wyrm

BertTheJasser 12-17-2006 10:29 AM

Collapse JASS:
set k=0.03/lumen[i].fade
give s me compile errors (grimoire, JassHelper 0.9.3), where lumen is a struct.
But
Collapse JASS:
set k=lumen[i].fade
set k=0.03/k
works as supposed, wihout errors.

Vexorian 12-17-2006 12:37 PM

So have you tested in 0.9.4?.


Blinkboy: I think case would be quite useless a.k.a the code would still be as slow or even allow the user to create really slow code

Edit: A similar code in 0.9.4 doesn't seem to cause errors

Ragnarok X 12-19-2006 12:10 PM

Why always the WEHelper internal preprocessor "define" get executed after your JassHelper preprocessor even if i put the define preprocessor before your own.

The main problem is that i want to remplace public or private variables and function with the define, but i cann't, or maybe you can with another preprocessador?.

Vexorian 12-19-2006 12:14 PM

It is a necessary evil

PipeDream 12-19-2006 09:02 PM

0.9.4 has put the fun back into JASS for me. It's easy to get fancy with data structures, although you have to do everything with lists and trees. Essentially it accomplishes the dynamic allocation/array passing dream in a manner far more practical than DARY.

It would be cool to have some type safety/casting, I keep mixing up structures.


All times are GMT. The time now is 01:53 AM.

Powered by vBulletin (Copyright ©2000 - 2020, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services