| 12-26-2006, 11:20 AM | #1 |
What I want to do is this: JASS://! library blah globals private integer array unit_id private integer array unit_id2 endglobals function weei takes nothing returns nothing // initialize unit_id2... // then... set unit_id=unit_id2 endfunction //! endlibrary Is this in possible in any way? |
| 12-26-2006, 11:25 AM | #2 |
In Jass, they have different names Private = Local Public = Global Declare globals like this: JASS:globals integer Hi = 0 integer array Bye = 0 endglobals Decale locals like this: JASS:function Hi takes nothing returns nothing local integer Hi = 0 local integer array Bye = 0 endfunction Using arrays, globals and locals: JASS:globals integer array SomeInteger = 0 endglobals function SomeFunction takes nothing returns nothing local integer SomeOtherInteger = SomeInteger[10] //[10] is the array index endfunction |
| 12-26-2006, 11:37 AM | #3 |
Tide remove from those JASS:integer array Bye = 0 integer array SomeInteger = 0 And Themerion you forgot to add the []'s, and yes, you can set a var = another var as long as they are compatible. ![]() |
| 12-26-2006, 12:05 PM | #4 |
You guys really missunderstood Themerion. Anyways, Themerion it is impossible to do that with the native arrays, you can always use CSCache's dynamic arrays or pipedream's DARY http://www.wc3campaigns.net/showthread.php?t=80534 http://www.wc3campaigns.net/showthread.php?t=87358 --- private and public are overwhelming different concepts to local and global. |
| 12-26-2006, 01:51 PM | #5 | |
Quote:
Local and globals are the closest you will get with private and public in Jass though. And Fireeye, i originally had it without the = 0, but as i havent used Jass in a few months, i wasent sure, but i remembered i had to give it a value somewhere, so i just thought there :P. |
| 12-26-2006, 02:24 PM | #6 | |
Quote:
He is using vJASS ... |
| 12-26-2006, 02:52 PM | #7 |
I will slowly make my way out of this thread, as i dont want to look any more like a fool than i already do. |
| 12-26-2006, 09:52 PM | #8 |
Why don't you tell us a bit about your application? It's likely what you want can be done most cleanly with graphs. |
| 12-27-2006, 04:46 PM | #9 | ||
Quote:
Graphs? ![]() The only graphs that I know about are illustrations of functions and equations. Such as y=ln x. y ^ |___/____ |__/_____ |_/______ |/_______ +---------> x y=x You don't mean these kinds of graphs, aight? :p Quote:
Very well... I'm using global unit-type arrays to store the unit types of heroes. Trigger: ![]() -------- Team 1 --------![]() Set HeroId_Human[1] = Admiral Proudmoore![]() Set HeroId_Human[2] = Sylvanas Windrunner![]() Set HeroId_Human[3] = Darth Vader![]() Set HeroId_Human[4] = Dracula![]() -------- Team 2 --------![]() Set HeroId_Naga[1] = Gloosh![]() Set HeroId_Naga[2] = Lady Vashj![]() Set HeroId_Naga[3] = Homer Simpson![]() Set HeroId_Naga[4] = runawaydroidThen, to assign a random hero to each player of each team I use: call RandomHeroes() JASS:// Using vJASS through JASSHelper with Grimoire. //! library RandomHeroes globals private integer count private integer start private boolean team private constant boolean NAGA=false private constant boolean HUMAN=true endglobals function RandomHero takes nothing returns nothing local integer uid if(team==NAGA) then set uid=udg_HeroId_Naga[1+ModuloInteger(count+start, 4)] else set uid=udg_HeroId_Human[1+ModuloInteger(count+start, 4)] endif call CreateUnit(GetEnumPlayer(),uid,GetPlayerStartLocationX(GetEnumPlayer()),GetPlayerStartLocationY(GetEnumPlayer()),0.0) set count=count+1 endfunction function RandomlyAssignHeroes takes force f, boolean t returns nothing set count=0 set start=GetRandomInt(1,4) set team=t call ForForce(f,function RandomHero) endfunction function RandomHeroes takes nothing returns nothing call RandomlyAssignHeroes(udg_Players_Naga,NAGA) call RandomlyAssignHeroes(udg_Players_Human,HUMAN) endfunction //! endlibrary In this specific case, I suppose that my wanted solution isn't particularily much more effective. However, what I wanted to do was of course to let the function RandomlyAssignHeroes take a force and a unit-type array (would be more logical). function RandomlyAssignHeroes takes force f, integer array heroId_array returns nothing |
| 12-27-2006, 05:18 PM | #10 |
Graphs are like networks , for example trees are graphs, It is kind of a whole branch of algorithm theory |
| 12-27-2006, 07:47 PM | #11 |
Lists seem to capture this application well. Most of the lines are getting the shuffle right and it's all mostly/hopefully reusable code. JASS:struct pair integer value pair next static method cons takes integer value, pair next returns pair local pair p = pair.create() set p.value = value set p.next = next return p endmethod method copy takes nothing returns pair if this.next == 0 then return pair.cons(this.value,0) else return pair.cons(this.value,this.next.copy()) endif endmethod //remove recursion static method Destroy takes pair p returns nothing local pair next = p.next call pair.destroy(p) if p.next != 0 then call pair.Destroy(next) endif endmethod endstruct struct list pair l static method Create takes nothing returns list local list s = list.create() set s.l = 0 return s endmethod method push takes integer value returns nothing set this.l = pair.cons(value,this.l) endmethod method pop takes nothing returns nothing if this.l != 0 then set this.l = this.l.next endif endmethod method peek takes nothing returns integer return this.l.value endmethod method isempty takes nothing returns boolean return this.l == 0 endmethod method shuffle takes nothing returns nothing local pair array lst local integer n = 0 local pair p = this.l local integer i = 0 local integer swapwith loop exitwhen p == 0 set lst[n] = p set n = n + 1 set p = p.next endloop loop exitwhen i >= n set swapwith = GetRandomInt(i,n-1) //swap ith with n-1th //need to include i so that every element can end up in every position set p = lst[swapwith] set lst[swapwith] = lst[i] set lst[i] = p set i = i + 1 endloop set i = 0 loop exitwhen i >= n-1 set lst[i].next = lst[i+1] set i = i + 1 endloop set lst[i].next = 0 set this.l = lst[0] endmethod //fine for acyclic method copy takes nothing returns list return this.l.copy() endmethod static method Destroy takes list l returns nothing call pair.Destroy(l.l) call list.destroy(l) endmethod endstruct JASS:globals list nagaheroes list humanheroes list heroes_enum endglobals function inithero takes nothing returns nothing set nagaheroes = list.Create() call nagaheroes.push('hfoo') call nagaheroes.push('hfoo') set humanheroes = list.Create() call humanheroes.push('hfoo') endfunction function RandomlyAssignHeroes_cb takes nothing returns nothing if heroes_enum.isempty() then call BJDebugMsg("Not enough heroes for players!") //break enum? probably need a var, don't bother endif call CreateUnit(GetEnumPlayer(),heroes_enum.peek(),0.,0.,0.) call heroes_enum.pop() endfunction //list heroes is passed humanheroes or nagaheroes function RandomlyAssignHeroes takes force f, list heroes returns nothing set heroes_enum = heroes.copy() //you don't need to copy if you don't use the lists again call heroes_enum.shuffle() call ForForce(f,function RandomlyAssignHeroes_cb) call list.Destroy(heroes_enum) endfunction |
| 12-28-2006, 09:26 PM | #12 |
So... now I have DynamicArrays versus lists. Lists require some minor code addons, while DynamicArrays depends on the Caster System ( which I will probably eventually have to add anyway ). DynamicArrays are "blazing"-fast, according to Vex's documentation. On the other hand, the same docs tell me that I shouldn't use them for global storage... Does it really matter which one of these I use? |
| 12-28-2006, 10:14 PM | #13 | |
Quote:
|
| 12-28-2006, 10:19 PM | #14 |
Please, stay on topic. Which is preferable for global constant arrays? lists _ or _ DynamicArrays |
| 12-28-2006, 10:30 PM | #15 | |
Quote:
Also, I'd say lists since dynamic arrays are for temporary use. |
