PDA

View Full Version : [JASS] Struct/Scope won't go on Init


Titanhex
07-15-2012, 08:58 AM
Alright, I tried rearranging the code here several ways and no matter what (Deleting scope, remove init from struct and putting it in scope with initializer, etc.) I couldn't get the debug message to fire. Obviously I"m doing something wrong (And I'm sure my code isn't very optimal so any pointers is appreciated)

Here it is. How do I get it to do the onInit like it's suppose to?

scope Locamotive

globals
private constant real tick = 0.1
endglobals

struct Drive

unit loco
real x
real y
real dur = 0
integer spot = 1
boolean forward = true
boolean moving = false
static real array pointX
static real array pointY

private static method Path takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
local real locoX = GetUnitX(.loco)
local real locoY = GetUnitY(.loco)
local real distance = SquareRoot((locoX - .x)*(locoX - .x) + (locoY - .y)*(locoY - .y))
call IssuePointOrder(.loco, "move", .x, .y)
if distance < 10 then
if .pointX[.spot+1] == 0 and .forward then
set .forward = false
elseif .pointX[.spot-1] == 0 and not .forward then
set .forward = true
endif
if .forward then
set .spot = .spot + 1
else
set .spot = .spot - 1
endif
set .x = .pointX[.spot]
set .y = .pointY[.spot]
call IssuePointOrder(.loco, "move", .x, .y)
endif
endmethod

private static method create takes nothing returns thistype
local thistype this = thistype.allocate()
local timer tim = NewTimerEx(this)
set .loco = gg_unit_subt_0578
set .x = .pointX[.spot]
set .y = .pointY[.spot]
call SetUnitPathing(.loco, false)
call TimerStart(tim, tick, true, function thistype.Path)
return this
endmethod

private static method onInit takes nothing returns nothing
set gg_trg_LocamotivePath = CreateTrigger()
call TriggerAddAction( gg_trg_LocamotivePath, function thistype.create )
debug call BJDebugMsg("GO!")
set pointX[1] = -9565
set pointY[1] = -15042
set pointX[2] = -9567
set pointY[2] = -14757
set pointX[3] = -9709
set pointY[3] = -14576
set pointX[4] = -10045
set pointY[4] = -14424
set pointX[5] = -10103
set pointY[5] = -13890
set pointX[6] = -9878
set pointY[6] = -13622
set pointX[7] = -9070
set pointY[7] = -13637
set pointX[8] = -8867
set pointY[8] = -13487
set pointX[9] = -8840
set pointY[9] = -13021
set pointX[10] = -8614
set pointY[10] = -12740
set pointX[11] = -7815
set pointY[11] = -12760
set pointX[12] = -7576
set pointY[12] = -13017
set pointX[13] = -7612
set pointY[13] = -13550
set pointX[14] = -7612
set pointY[14] = -15250
set pointX[15] = -7379
set pointY[15] = -15500
set pointX[16] = -7150
set pointY[16] = -15500
set pointX[17] = -6000
set pointY[17] = -15500
set pointX[18] = -4950
set pointY[18] = -15500
set pointX[19] = -4400
set pointY[19] = -15500
set pointX[20] = -4150
set pointY[20] = -15250
set pointX[21] = -4135
set pointY[21] = -14300
set pointX[22] = -3900
set pointY[22] = -14020
set pointX[23] = -3190
set pointY[23] = -14025
set pointX[24] = -2770
set pointY[24] = -13585
set pointX[25] = -2650
set pointY[25] = -13530
set pointX[26] = -2150//Station East
set pointY[26] = -13530
/* set pointX[27] =
set pointY[27] =
set pointX[28] =
set pointY[28] =
set pointX[29] =
set pointY[29] =
set pointX[30] =
set pointY[30] =
set pointX[31] =
set pointY[31] =
set pointX[32] =
set pointY[32] =
set pointX[33] =
set pointY[33] =
set pointX[34] =
set pointY[34] =
set pointX[35] =
set pointY[35] =
set pointX[36] =
set pointY[36] =
set pointX[37] =
set pointY[37] =
set pointX[38] =
set pointY[38] =
set pointX[39] =
set pointY[39] =
set pointX[40] =
set pointY[40] =
set pointX[41] =
set pointY[41] =
set pointX[42] =
set pointY[42] =
set pointX[43] =
set pointY[43] =
set pointX[44] =
set pointY[44] =
set pointX[45] =
set pointY[45] =
set pointX[46] =
set pointY[46] =
set pointX[47] =
set pointY[47] =
set pointX[48] =
set pointY[48] =
set pointX[49] =
set pointY[49] =
*/ endmethod

endstruct

endscope

WaterKnight
07-15-2012, 10:25 AM
Is debug mode on? Do other inits work? Have you a custom main function? Make sure it does not crash.

Deaod
07-15-2012, 01:22 PM
Add a wait in front of your debug message. If you can see the message then, youre fine. The onInit was executed.

mckill2009
07-15-2012, 01:32 PM
what is the name of your trigger? I mean when you press CTRL+T, if it's not 'LocamotivePath', then your code
will cause error since gg_trg_LocamotivePath is a generated/preplaced global trigger which doesnt exist if your triggername is not LocamotivePath...

Troll-Brain
07-15-2012, 02:49 PM
You are likely crashing the thread in the main function, most likely an other previous vJass initializer which causes a thread crash, like reaching the limit op or use an undefined variable, or whatever else.
Put a debug message in each vJass initializer begin and end and see what happens.

Magtheridon96
07-15-2012, 04:02 PM
Just remove the debug keyword and try it out. Maybe you don't have Debug-mode on.

Also,

You are likely crashing the thread in the main function, most likely an other previous vJass initializer which causes a thread crash

This.

edit
It would be funny if it turns out that you're clearing the screen in an init function that runs after this one :P

Troll-Brain
07-15-2012, 04:33 PM
Oh yes forgot the most obvious reason, the debug mode setted to off.
But well i just assumed that the code dind't started at all, because if it's only a matter of debug mode setted on or off, then the map script has 0 problem :p

Also i'm wondering if a such crash is possible with Cohadar's jasshelper (if each vJass initializer is called with an ExecuteFunc or not)

Titanhex
07-15-2012, 04:44 PM
Fixed the other thread, thanks all, now the problem is thistype.create doesn't seem to want to fire.

Magtheridon96
07-15-2012, 04:51 PM
Well, yes, it's not supposed to fire.
There was no event registered to the trigger :p
If you want it to run during init, you can simply call thistype.create() and it will run.

Titanhex
07-15-2012, 04:55 PM
Ahh okay. I was setting it up like a typical GUI trigger, which obviously was incorrect.

Magtheridon96
07-15-2012, 04:58 PM
Yeah, I figured that :P
I used to do the same mistake about 1.2 years ago.