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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +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