brand new jass beginner +rep for help

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
ok when you use
JASS:
local a = struct.create

it creates a struct instance and you can use the variable a to get that structs intsance number, and you can use that number in any trigger to get that instance correct?

and that instance can store multiple variables, so its essentially like a hashtable in gui
 

Dirac

22710180
Reaction score
147
No, hashtables are the same for gui and for jass.

It's like an array variable on your variable editor.

the number that struct.create returns is the index the array takes

array[index]=value

index.array=value

this.number=value
 

luorax

Invasion in Duskwood
Reaction score
67
Something like this:

JASS:
local <type> <name> = <type>.create(<arguments)
local thistype this=thistype.create()
local Data d=Data.create(u,150.)


But yes, you got the point. Because structs are basically arrays, the struct instance is an integer, that represents the index of the instance. So when you're trying to get a struct member like this:

JASS:
call KillUnit(Data(this).owner)


it's converted to something like this:

JASS:
call KillUnit(s_Data_owner[this])


If you take a look at the popular vJASS systems, you'll notice that everytime you see a "data" field, it's always an integer. Well, this is the reason. You can always create a dummy struct, create a new instance and store everything necessary in it (or later you'll be able to work only with structs), so that you can retrieve it later, when needed. It's actually a very powerful thing IMO.

EDIT:
JASS:
call KillUnit(Data(this).owner)


is equal to:

JASS:
local Data d=this
call KillUnit(d.owner)


It's called typecasting.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
alright this is my example of using a struct to store stats for an rpg, just an example:
JASS:
struct UnitIndex
  unit IndexedUnit
  real CritChance
  real DodgeChance
endstruct
JASS:
//here we determine the crit/dodge chance
function CritChanceArith takes unit u returns real
  return (SquareRoot(I2R(GetHeroAgi( u, true))) + SquareRoot(I2R(GetHeroInt( u, true)))) x 2
endfunction

function DodgeChanceArith takes unit a returns real
  return SquareRoot(I2R(GetHeroAgi( u, true))) x 3
endfunction

//this down here is the function i would call to create the struct
function SaveNewHero takes nothing returns nothing
  local a = UnitIndex.create()
  call SetUnitUserData( GetTriggerUnit, a)
  set GetUnitUserData.IndexedUnit = GetTriggerUnit
  set GetUnitUserData.CritChance = CritChanceArith(GetTriggerUnit)
  set GetUnitUserData.DodgeChance = DodgeChanceArith(GetTriggerUnit)
endfunction
 

Laiev

Hey Listen!!
Reaction score
188
Jass is case sensitive

JASS:
struct UnitIndex
  unit IndexedUnit
  real CritChance
  real DodgeChance
endstruct


and this

JASS:
function SaveNewHero takes nothing returns nothing
  local a = UnitIndex.create
  call SetUnitUserData( GetTriggerUnit, a)
  set GetUnitUserData.IndexedUnit = GetTriggerUnit
  set GetUnitUserData.CritChance = CritChanceArith(GetTriggerUnit)
  set GetUnitUserData.DodgeChance = DodgeChanceArith(GetTriggerUnit)
endfunction

//>

function SaveNewHero takes nothing returns nothing
  local UnitIndex a = UnitIndex.create() //you forget the type
  //call SetUnitUserData( GetTriggerUnit, a) // don't do this, you'll bug every index system
  set a.IndexedUnit = GetTriggerUnit
  set a.CritChance = CritChanceArith(a.IndexedUnit)
  set a.DodgeChance = DodgeChanceArith(a.IndexedUnit)
endfunction
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
why would using the unit's custom value bug the index system? if i was making my own system to index units
 

luorax

Invasion in Duskwood
Reaction score
67
JASS:
struct DamageData
    unit unit
    real critChance
    real dodgeChance
endstruct

function CritChanceArith takes unit a returns real
    return (SquareRoot(I2R(GetHeroAgi(u,true)))+SquareRoot(I2R(GetHeroInt(u,true))))*2
endfunction

function DodgeChanceArith takes unit a returns real
    return SquareRoot(I2R(GetHeroAgi(u,true)))*3
endfunction

function SaveNewHero takes nothing returns nothing
    local DamgeData a=DamgeData.create()
    set a.unit= GetTriggerUnit()
    set a.critChance=CritChanceArith(a.unit)
    set a.dodgeChance=DodgeChanceArith(a.unit)
    call SetUnitUserData(a.unit,a)
endfunction

// or something similar to your example, just to see how typecasting works;
// note that the one above is way faster

function SaveNewHero takes nothing returns nothing
    local DamgeData a=DamgeData.create()
    call SetUnitUserData(GetTriggerUnit(),a)
    set DamgeData(GetUnitUserData(GetTriggerUnit())).unit= GetTriggerUnit()
    set DamgeData(GetUnitUserData(GetTriggerUnit())).critChance=CritChanceArith(GetTriggerUnit())
    set DamgeData(GetUnitUserData(GetTriggerUnit())).dodgeChance=DodgeChanceArith(GetTriggerUnit())
endfunction


However I'd do it like this:

JASS:
struct DamageData
    unit unit
    real critChance
    real dodgeChance
    method getCritChance takes nothing returns real
        return (SquareRoot(I2R(GetHeroAgi(this.unit,true)))+SquareRoot(I2R(GetHeroInt(this.unit,true))))*2
    endmethod
    method getDodgeChance takes nothing returns real
        return SquareRoot(I2R(GetHeroAgi(this.unit,true)))*3
    endmethod
    static method create takes unit u returns thistype
        local thistype this=thistype.allocate()
        set this.unit=u
        set this.critChance=this.getCritChance()
        set this.dodgeChance=this.getDodgeChance()
        call SetUnitUserData(this.unit,this)
        return this
    endmethod
endstruct

function SaveNewHero takes nothing returns nothing
    call DamageData.create(GetTriggerUnit())
endfunction


Now take a deep breath, then try to figure out what and why I did in my example.

EDIT:

why would using the unit's custom value bug the index system? if i was making my own system to index units

Because indexing systems use the unit's user data to attach the unit's index to the unit. Overwriting it would obviously bug the system.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
i understand what you did, you used methods to set the values within the struct rather than using a return from another function then saved them using a static method that way you only save the unit and not all the information

and i was meaning, what if this was my index system, thats how i wanted to treat it, not like i was using someone elses

ill check it out at home ayanami, blocked at work :/

what does this.something stand for? i assume it means that instance but i want to be sure
 

luorax

Invasion in Duskwood
Reaction score
67
"this" represents the actual instance. It's only available in non-static methods, however you can declare it in statics manually.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
and thats declared with the line: local thistype this=thistype.allocate
correct?

how am i doing so far for having started jass almost exactly 7 days ago?
 

tooltiperror

Super Moderator
Reaction score
231
Don't ask how you are doing. Judge yourself, and being "good" at Jass doesn't really matter.

Naming conventions are very important, by way of constants you can find the scope and context of a variable without finding where it is declared.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
i meant more where should i be headed from here, what would the next step be, not am i like super super good... sorry if i stated the question wrong, ill read up on conventions tomorow when i have all day to zonk out at home

how do i add events and conditions to a function? i understand how to call functions with actions, but iv never actually added conditions at this point
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
i see, thats easy enough, thanks lol
what would a condition function look like?
 

Laiev

Hey Listen!!
Reaction score
188
JASS:
function SomeAction takes nothing returns nothing
endfunction
function SomeCondition takes nothing returns boolean
    return false //action will not be executed, if return true, action will be executed
endfunction
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
can a struct have an array in one of the variables encapsulated?

ie:
JASS:
struct example
  real x[10]//<--- to save 10 arrays in a single instance
endstruct
 

Ayanami

칼리
Reaction score
288
can a struct have an array in one of the variables encapsulated?

ie:
JASS:
struct example
  real x[10]//<--- to save 10 arrays in a single instance
endstruct

Using array instance members decreases the total instances that you can have. It's 8190 by default. If I'm not wrong, by declaring a instance member with array size of 10, your max instances become 819.
 

Dirac

22710180
Reaction score
147
As Ayanami says it does that because it "simulates" 2d arrays, but you're really only using 1 array and split it in 10 parts (in that case). I advise you to not do that ever, if you want to store multiple values, learn some about linked lists (i should probably write a tutorial about that too).
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
the idea i had would only store values for heroes, so if a legit map has over 819 heroes at one time, im pretty sure the maker should be shot in the face, not 100% on that one though lol

and is there a way to change the variables stored by a struct and add/remove more to/from it after the game has started
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top