What's an example of attaching a struct to a trigger?

Status
Not open for further replies.

MasterRofl

New Member
Reaction score
8
Sure, I know how to attach a struct to a handle just fine, but how would you do it with a trigger?

EDIT: Shoot, forgot to mention, using ABC.
 

Romek

Super Moderator
Reaction score
964
Triggers are handles.. So yeah :p
 
Reaction score
333
First, replace (in ABC):

JASS:
//! runtextmacro ABC("A","Timer","timer")
//! runtextmacro ABC("B","Timer","timer")
//! runtextmacro ABC("C","Timer","timer")

//! runtextmacro ABC("A","Trigger","trigger")
//! runtextmacro ABC("B","Trigger","trigger")
//! runtextmacro ABC("C","Trigger","trigger")

//! runtextmacro ABC("A","Dialog","dialog")
//! runtextmacro ABC("B","Dialog","dialog")
//! runtextmacro ABC("C","Dialog","dialog")

//! runtextmacro ABC("A","Region","region")
//! runtextmacro ABC("B","Region","region")
//! runtextmacro ABC("C","Region","region")

private function Init takes nothing returns nothing
call InitTimerHashA()
call InitTimerHashB()
call InitTimerHashC()

call InitTriggerHashA()
call InitTriggerHashB()
call InitTriggerHashC()

call InitDialogHashA()
call InitDialogHashB()
call InitDialogHashC()

call InitRegionHashA()
call InitRegionHashB()
call InitRegionHashC()
endfunction


With:

JASS:
//! runtextmacro ABC("A","Handle","handle")

private function Init takes nothing returns nothing
    call InitHandleHashA()
endfunction


Now you should be able to use SetHandleStructA to attach to any handle type (trigger, timer, dialog, trackable, etc).

JASS:
function foo takes nothing returns nothing
    local trigger t = CreateTrigger()
    local SomeStruct d = SomeStruct.create()
    call SetHandleStructA(t, d)
endfunction
 

MasterRofl

New Member
Reaction score
8
Um, I meant for a trigger... like how you would do this to get the attached struct for a timer:
JASS:
local timer t = GetExpiredTimer()
local struct s = GetTimerStructA(t)


How would you "Get" the struct for a trigger?
 
Reaction score
333
Well, like I said, if you replace all the useless superfluous textmacro calls with a single one for handles you can use GetHandleStructA, SetHandleStructA and ClearHandleStructA for any handle type.

EDIT: Or do you mean how to acquire a trigger? You can use GetTriggeringTrigger() in a trigger's actions or conditions to acquire a reference to it.
 

Cohadar

master of fugue
Reaction score
209
Do NOT do what TheDamien just did.
Doing direct handle attachments is a railroad to hell.

What you need is:
local Data dat = GetTriggerStructA(GetTriggeringTrigger())
 
Reaction score
333
Do NOT do what TheDamien just did.
Doing direct handle attachments is a railroad to hell.

No it is not. Everyone else manages direct handle attachment fine, and I have never seen a compelling reason to use subtype-specific attachment.
 

Cohadar

master of fugue
Reaction score
209
That is because you never made any real maps.
And if there was no compelling reason for type-safety people would be programming in assembler now, not in strong-type languages we have today.
 
Reaction score
333
That is because you never made any real maps.

Unless you are suggesting that my use of handle type attachment systems is responsible for my vapourmapping, I don't see how this is relevant. There are hundreds of successful maps that use handle attachment, so this really doesn't cut it as an argument.

And if there was no compelling reason for type-safety people would be programming in assembler now, not in strong-type languages we have today.

Yet many strongly typed languages we use today allow us to treat subtypes and subclasses as parent types/classes. ABC does not offer extra type-safety merely because you declare it so.
 

Cohadar

master of fugue
Reaction score
209
Unless you are suggesting that my use of handle type attachment systems is responsible for my vapourmapping, I don't see how this is relevant. There are hundreds of successful maps that use handle attachment, so this really doesn't cut it as an argument.
It is relevant because you start to appreciate type safety only when you spend hours debugging attachment code.
And what are those hundreds of successful maps you are talking about?
I know only 5-10 successful maps and half of them don't even use attaching while other half uses type-safety attaching.
Even DotA-Allstars uses a type-safe gamecache library.

Yet many strongly typed languages we use today allow us to treat subtypes and subclasses as parent types/classes. ABC does not offer extra type-safety merely because you declare it so.
subtypes are specialization, using handles is generalization, it goes in the opposite direction (up the type tree) so I guess your point is in my favor here..

And ABC does offer extra type-safety because I declare it so.
 
Reaction score
333
It is relevant because you start to appreciate type safety only when you spend hours debugging attachment code.

I have had problems with attachment code in the past, but all were solved and completely unrelated to type errors cause by handle attachment. It is odd that you are the only one to run into problems with it, why don't you elaborate?

And what are those hundreds of successful maps you are talking about?
I know only 5-10 successful maps and half of them don't even use attaching while other half uses type-safety attaching.
Even DotA-Allstars uses a type-safe gamecache library.

Do you simply make things up to support your position? DotA uses a HandleVars variant, which is not type-safe (in an unrelated way) because of the many I2H functions.

subtypes are specialization, using handles is generalization, it goes in the opposite direction (up the type tree) so I guess your point is in my favor here..

No it does not. Using handles in this regard is simply a form of type polymorphism. H2I will return the same ID whether something is typed as handle or one of its subtypes. Nothing within the actual attachment system relies on subtype-specific properties to function correctly.
 

Cohadar

master of fugue
Reaction score
209
Great now that you lost your arguments you call me a liar above all.
And your use of "big" programming words does not help your either, it only makes you look silly to anyone who knows the subject.

I said all I wanted to say on the subject, you can argue with yourself now.
 
Reaction score
333
Great now that you lost your arguments you call me a liar above all.

If you can't offer a single reason or construct a single argument in the way of why ABC's method is so much more type safe than attachment to handles, then there isn't really an argument for me to "lose".

What you said about DotA was simply false, so I just reached the obvious conclusion. There are many less flattering conclusions I could have reached.

And your use of "big" programming words does not help your either, it only makes you look silly to anyone who knows the subject.

Do you disagree that being able to use a subtype as its parent type is type polymorphism, then? Why don't you provide a brief explanation of why this is wrong?

I said all I wanted to say on the subject, you can argue with yourself now.

I'll correct you here: You've said everything that you can say on the subject, which basically amounts to "handle attachment is not type-safe for a mysterious and unspecified reason, known only to me, which I am unwilling to elaborate on or explain to anyone."
 

quraji

zap
Reaction score
144
Great now that you lost your arguments you call me a liar above all.
And your use of "big" programming words does not help your either, it only makes you look silly to anyone who knows the subject.

You've called me a liar before :p
And I'm wondering what type of words should someone use to describe programming, if not programming words?

So is type-safety what ABC is all about? I suppose I should at least look at popular systems. As a note, I've never run problems with handle attaching.

Anywho, as much as I love a good geek fight...break it up, eh? ;)

P.S. - I support gamecache :thup:
 

Cohadar

master of fugue
Reaction score
209
What you said about DotA was simply false, so I just reached the obvious conclusion. There are many less flattering conclusions I could have reached.

Hahhhahaa, tell me Damien how did you become such an expert on dota code, did IceFrog give you the source :D

For those interested here is part of dota script:
JASS:

function InitDTAXCache takes nothing returns nothing
	call FlushGameCache(InitGameCache("DotACache.x"))
	set udg_gc_DTAX_Cache=InitGameCache("DotACache.x")
endfunction

function H2I takes handle h returns integer
	return h
	return 0
endfunction

function H2S takes handle h returns string
	return I2S(H2I(h))
endfunction

function FlushStoredMissionShell takes string sMission returns nothing
	call FlushStoredMission(udg_gc_DTAX_Cache,sMission)
endfunction

function StoreDTAXObject takes string sMission,string sKey,handle hObject returns nothing
	call StoreInteger(udg_gc_DTAX_Cache,sMission,sKey,H2I(hObject))
endfunction

function StoreDTAXInteger takes string sMission,string sKey,integer iInteger returns nothing
	call StoreInteger(udg_gc_DTAX_Cache,sMission,sKey,iInteger)
endfunction

function StoreDTAXInteger_Copy takes string sMission,string sKey,integer iInteger returns nothing
	call StoreInteger(udg_gc_DTAX_Cache,sMission,sKey,iInteger)
endfunction

function StoreDTAXReal takes string sMission,string sKey,real rReal returns nothing
	call StoreReal(udg_gc_DTAX_Cache,sMission,sKey,rReal)
endfunction

function StoreDTAXBoolean takes string sMission,string sKey,boolean bBoolean returns nothing
	call StoreBoolean(udg_gc_DTAX_Cache,sMission,sKey,bBoolean)
endfunction

function GetStoredDTAXUnit takes string sMission,string sKey returns unit
	return GetStoredInteger(udg_gc_DTAX_Cache,sMission,sKey)
	return null
endfunction

function GetStoredDTAXPlayer takes string sMission,string sKey returns player
	return GetStoredInteger(udg_gc_DTAX_Cache,sMission,sKey)
	return null
endfunction

function GetStoredDTAXTimer takes string sMission,string sKey returns timer
	return GetStoredInteger(udg_gc_DTAX_Cache,sMission,sKey)
	return null
endfunction

function GetStoredDTAXTrigger takes string sMission,string sKey returns trigger
	return GetStoredInteger(udg_gc_DTAX_Cache,sMission,sKey)
	return null
endfunction

function GetStoredDTAXGroup takes string sMission,string sKey returns group
	return GetStoredInteger(udg_gc_DTAX_Cache,sMission,sKey)
	return null
endfunction

function GetStoredDTAXEffect takes string sMission,string sKey returns effect
	return GetStoredInteger(udg_gc_DTAX_Cache,sMission,sKey)
	return null
endfunction

function GetStoredDTAXLocation takes string sMission,string sKey returns location
	return GetStoredInteger(udg_gc_DTAX_Cache,sMission,sKey)
	return null
endfunction

function GetStoredDTAXTriggerAction takes string sMission,string sKey returns triggeraction
	return GetStoredInteger(udg_gc_DTAX_Cache,sMission,sKey)
	return null
endfunction

function GetStoredDTAXInteger takes string sMission,string sKey returns integer
	return GetStoredInteger(udg_gc_DTAX_Cache,sMission,sKey)
endfunction

function GetStoredDTAXInteger_Copy takes string sMission,string sKey returns integer
	return GetStoredInteger(udg_gc_DTAX_Cache,sMission,sKey)
endfunction

function GetStoredDTAXReal takes string sMission,string sKey returns real
	return GetStoredReal(udg_gc_DTAX_Cache,sMission,sKey)
endfunction

function GetStoredDTAXBoolean takes string sMission,string sKey returns boolean
	return GetStoredBoolean(udg_gc_DTAX_Cache,sMission,sKey)
endfunction
Of course it does not look this pretty after game gets optimized,
then it looks like this:
JASS:

function OI0110 takes string OI0O00,string OI00I0 returns unit
return GetStoredInteger(OOII,OI0O00,OI00I0)
return null
endfunction
function OIIOO0 takes string OI0O00,string OI00I0 returns player
return GetStoredInteger(OOII,OI0O00,OI00I0)
return null
endfunction
function OIIO00 takes string OI0O00,string OI00I0 returns timer
return GetStoredInteger(OOII,OI0O00,OI00I0)
return null
endfunction
function OIIOI0 takes string OI0O00,string OI00I0 returns trigger
return GetStoredInteger(OOII,OI0O00,OI00I0)
return null
endfunction
function OIIO10 takes string OI0O00,string OI00I0 returns group
return GetStoredInteger(OOII,OI0O00,OI00I0)
return null
endfunction
function OII0O0 takes string OI0O00,string OI00I0 returns effect
return GetStoredInteger(OOII,OI0O00,OI00I0)
return null
endfunction
// and so on....

If there is anyone that do not believe me go to www.getdota.com, download the latest version and extract the war3map.j file.
There is a number of tools that can do this, one of them is jasshelper.

Now people please share some -rep with our ignorant friend TheDamien, it will help him become a better man.
 
Reaction score
333
Perhaps Cohadar would like to look at the DotA map script and notice the typecasting from integer to various handle types (an actual and very well known type-safety concern). In the process he might also notice that attachment is exactly the same whether you attach to a trigger, a widget, a timer or any other type of handle, and that the functions only differ for the data being attached.

Even DotA-Allstars uses a type-safe gamecache library.

So, once again, this is simply false. The imaginary type-safety advantage that ABC supposedly provides by having different functions for each handle type to attach to is completely lacking in DotA's HandleVars, and the REAL type-safety advantage of I2Hless attachment is also missing.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
The answer to the original question has been given.


I suggest to continue this quarrel through PMs, Cohadar and TheDamien.

If at all.
 
Status
Not open for further replies.
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top