| 04-27-2008, 05:19 PM | #1 |
I've tried finding the answer on forums and tutorials, but cannot find exactly what I need Here's my question: how do I use structs to pass information between functions? In this simple projectile I'm making I want to pass a unit and variable through another function using a struct, but I'm not sure how JASS:struct projectile unit missile = null real damage = 0 endstruct function LivingFlameExplode takes nothing returns nothing if IsUnitEnemy(GetTriggerUnit(),GetOwningPlayer(udg_Elementalist)) then call PolledWait(0.25) // I want to call the unit "missile" in the function below // call CollisionMissile_Destroy(projectile.missile) endif endfunction function Trig_CS_Living_Flame_Actions takes nothing returns nothing local real r = 0.1 local unit u = GetTriggerUnit() local real level = GetUnitAbilityLevel(u,'A00A') local real damage = level*45 local location targetloc = GetSpellTargetLoc() local location casterloc = GetUnitLoc(u) local real angle = AngleBetweenPoints(casterloc,targetloc) local real x = GetLocationX(casterloc)+Cos(angle*bj_DEGTORAD)*100 local real y = GetLocationY(casterloc)+Sin(angle*bj_DEGTORAD)*100 //The unit I want to store for later local unit missile = CollisionMissile_Create("Abilities\\Weapons\\RedDragonBreath\\RedDragonMissile.mdl",x,y,angle, 1, 0, 1200, 50, false, 50, function LivingFlameExplode) local projectile livingflame = projectile.create() set livingflame.missile = missile set livingflame.damage = damage call DisplayTextToForce( GetPlayersAll(), R2S(angle) ) loop exitwhen r > 1 call SetUnitScale(livingflame.missile,r,r,r) set r = r+0.1 call PolledWait(0.1) endloop call CollisionMissile_SetSpeed(missile,60) endfunction |
| 04-27-2008, 05:42 PM | #2 |
struct = integer pointer (id) so.. function xxx takes integer my_struct or function xxx takes my_struct_name my_struct will be the same (but the preproccesor does need the type info to be able to do OO operations like set my_struct.x=234 // just an example ) thats why it's bad to use Jasshelper for low skilled users in jass. they simply can't reinerpritate the same code to jass in their mind. = confusing. |
| 04-27-2008, 05:42 PM | #3 |
How is the function you want ot pass it to called...? |
| 04-27-2008, 05:48 PM | #4 |
@ToadCop: sorry that explanation doesn't make much sense to me. @Griff: JASS:local unit missile = CollisionMissile_Create("Abilities\\Weapons\\RedDragonBreath\\RedDragonMissile.mdl",x,y,angle, 1, 0, 1200, 50, false, 50, function LivingFlameExplode) this is a Vexorian function, the last code taken is the callback function when the created missile collides with another unit. I need to destroy the missile in the function LivingFlameExplode, but I don't know how to use structs to get the variable referring to the missile i just created. |
| 04-27-2008, 06:53 PM | #5 |
Passing Structs through Functions == Passing Integers through Functions ... how to do this is your decision. gamecache, arrays, some specific systems etc. this function does create a trigger/timer with this callback function (code) so you need to "attach" this data to this trigger/timer. // kind a stupid to use something what you don't understand how it works. |
| 04-27-2008, 10:50 PM | #6 |
Ok, my question is how do I attach data to the trigger. I'm not wondering how it works, I'm asking how it can be done (i.e. HOW do I attach a struct to the trigger) Also, I'm intentionally using something I don't understand so I can learn by doing. It's called educating yourself. |
| 04-27-2008, 11:10 PM | #7 | |
Quote:
CollisionMissiles got _SetTag and _GetTag functions. There's also a GetTriggerCollisionMissile() function so: JASS://next time, make this private, inside a scope.... struct projectile unit missile = null real damage = 0 endstruct function LivingFlameExplode takes nothing returns nothing local unit m=GetTriggerCollisionMissile() local projectile P = projectile(CollisionMissile_GetTag(m)) //notice the type cast (See jasshelper's readme) //you didn't need to get the missile struct to destroy it, but you most likely needed it for damage //and to actually destroy the struct, else it leaks... if IsUnitEnemy(GetTriggerUnit(),GetOwningPlayer(udg_Elementalist)) then // I don't think waits work in CollisionMissile hit events? //BTW the wait would make the trigger happen multiple times, you probably don't want that //call PolledWait(0.25) //do damage? call CollisionMissile_Destroy(m) //read the entire collision missile documentation next time... call P.destroy() endif endfunction function Trig_CS_Living_Flame_Actions takes nothing returns nothing local real r = 0.1 local unit u = GetTriggerUnit() local real level = GetUnitAbilityLevel(u,'A00A') local real damage = level*45 local location targetloc = GetSpellTargetLoc() local location casterloc = GetUnitLoc(u) local real angle = AngleBetweenPoints(casterloc,targetloc) local real x = GetLocationX(casterloc)+Cos(angle*bj_DEGTORAD)*100 local real y = GetLocationY(casterloc)+Sin(angle*bj_DEGTORAD)*100 //The unit I want to store for later local unit missile = CollisionMissile_Create("Abilities\\Weapons\\RedDragonBreath\\RedDragonMissile.mdl",x,y,angle, 1, 0, 1200, 50, false, 50, function LivingFlameExplode) local projectile livingflame = projectile.create() call CollisionMissile_SetTag(missile , livingflame) set livingflame.missile = missile set livingflame.damage = damage call DisplayTextToForce( GetPlayersAll(), R2S(angle) ) loop exitwhen r > 1 call SetUnitScale(livingflame.missile,r,r,r) set r = r+0.1 call PolledWait(0.1) endloop call CollisionMissile_SetSpeed(missile,60) //#don't forget to destroy the missile...# endfunction |
| 04-27-2008, 11:29 PM | #8 | |
Quote:
btw i am interesed self if you can find where i have created a thread with a question... hmmm maybe but i can't remember now. + using alot of "what you don't understand" may lead you to "fatal" problems... first try to find out how it does work and after use it. it's just a hint. (but it obvious) |
| 04-27-2008, 11:54 PM | #9 |
Ah GetTriggerCollisionMissile was the function I needed. I was using this as a experiment to teach myself structs, but I can just as easily use some globals to fill in the damage. I looked through your notes, but I guess I glossed over that function, thanks Vex. I'm sorry ToadCop, but I am offended by your judgement that I am stupid to ask for help after trying to do something myself and failing. I am trying to learn vJass, and part of that is being willing to go outside one's zone of comfort and ocassionally fail. Unless you truly make an effort to help me, please keep those comments to yourself. |
| 04-28-2008, 03:27 AM | #10 | |
Quote:
I like how CollisionMissiles got so over complicated with time, good that I might have a cs replacement coming soon... Anyways, Castlemaster got served so there's no reason to keep this open. |
