Bships Code Error

Do you need World Editor help? Ask here!
Before making a new topic:
First, check if your question has already been answered in the Tutorials section.
If you didn't find a solution, use the search function.
If searching didn't help either, you can make a new topic.

Topic title & content:
You must use a descriptive title. (Help plz is not good) (Need help with Dialog buttons is good)
Go into much detail when posting. You should post attachments. Like screenshots of the problem, the map you are making, replays of the error. Or you could even make a screencast (video) of your problem and upload it here.

Spelling:
Grammar seems to be a serious problem amongst teenagers, so use a spell checker or you will get no love.
Read your posts twice, before pressing the reply button.
And do not use profanity. Chatspeak (y r u nub) and Leetspeak (1 C4N S33 H4X) are not welcome here either.

Only World Editor related questions are allowed here!
(Click for Battle.net help) (Click for World Editor help)

Re: Bships Code Error

New postby 3ICE on Wed May 13, 2009 3:39 am

ikillforeyouare you sure you cant just look through the code and try to find a way to make it use passive items?
Oh the expectations...

No, I'm at the end of my school year, taking exams in all the 15 subjects I took up. The worst ones (lit,gram,com,etc) are not even done yet. The rest (math,ph,comp,prog,typ,lang,etc) were/will be easy. I have 13 exams to go.
ImageImageImageImageImage
Image
ImageImage
User avatar
3ICE
Admin
 
Posts: 2359
Joined: Sat Mar 01, 2008 11:34 pm
Location: Hungary
Realm: US East
Account: 3ICE
Clan: 3ICE

Re: Bships Code Error

New postby ikillforeyou on Sun May 24, 2009 1:30 pm

ok then, i have another question about the trigger from that map. How did he get the dummy units to follow the ship? wouldn't a trigger that uses a periodic event and unit - move make lag? it would also make it so that the ship couldn't fire while moving.
can you answer that?
ikillforeyou
 
Posts: 30
Joined: Sat Nov 22, 2008 4:10 pm

Re: Bships Code Error

New postby 3ICE on Sun May 24, 2009 1:51 pm

ikillforeyouHow did he get the dummy units to follow the ship?
He used a periodic event, which is very laggy indeed. And the unhandled memory leaks don't help either. :)

I'll edit this post with extracted code once I'm done with my WinXP reinstall for a client (approx 30 mins).

EDIT: So here is the promised code:
(Don't read this, because I split it into three smaller parts for easier digesting. Scroll down to find them.)
Code: Select all
//===========================================================================
// Trigger: Weapon Move 1
//===========================================================================
function Trig_Weapon_Move_1_Func001A takes nothing returns nothing
    call SetUnitPositionLoc( udg_PlayerShip_Control[GetConvertedPlayerId(GetEnumPlayer())], GetUnitLoc(udg_PlayerShip[GetConvertedPlayerId(GetEnumPlayer())]) )
endfunction

function Trig_Weapon_Move_1_Actions takes nothing returns nothing
    call ForForce( GetPlayersAll(), function Trig_Weapon_Move_1_Func001A )
endfunction

//===========================================================================
function InitTrig_Weapon_Move_1 takes nothing returns nothing
    set gg_trg_Weapon_Move_1 = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Weapon_Move_1, 2.00 )
    call TriggerAddAction( gg_trg_Weapon_Move_1, function Trig_Weapon_Move_1_Actions )
endfunction

//===========================================================================
// Trigger: Weapon Move 2
//===========================================================================
function Trig_Weapon_Move_2_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetAttacker()) == 'u00P' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Weapon_Move_2_Func001A takes nothing returns nothing
    call SetUnitPositionLoc( GetEnumUnit(), PolarProjectionBJ(GetUnitLoc(udg_PlayerShip[GetConvertedPlayerId(GetOwningPlayer(GetAttacker()))]), GetRandomReal(0.00, 128.00), GetRandomReal(0.01, 360.00)) )
    call IssueTargetOrderBJ( GetEnumUnit(), "attack", udg_PlayerShip_Target[GetConvertedPlayerId(GetOwningPlayer(GetAttacker()))] )
endfunction

function Trig_Weapon_Move_2_Actions takes nothing returns nothing
    call ForGroupBJ( udg_PlayerShip_Cannons[GetConvertedPlayerId(GetOwningPlayer(GetAttacker()))], function Trig_Weapon_Move_2_Func001A )
endfunction

//===========================================================================
function InitTrig_Weapon_Move_2 takes nothing returns nothing
    set gg_trg_Weapon_Move_2 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Weapon_Move_2, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Weapon_Move_2, Condition( function Trig_Weapon_Move_2_Conditions ) )
    call TriggerAddAction( gg_trg_Weapon_Move_2, function Trig_Weapon_Move_2_Actions )
endfunction

//===========================================================================
// Trigger: Weapon Move 3
//===========================================================================
function Trig_Weapon_Move_3_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetAttacker(), UNIT_TYPE_ANCIENT) == true ) ) then
        return false
    endif
    if ( not ( DistanceBetweenPoints(GetUnitLoc(GetAttacker()), GetUnitLoc(udg_PlayerShip[GetConvertedPlayerId(GetOwningPlayer(GetAttacker()))])) > 256.00 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Weapon_Move_3_Actions takes nothing returns nothing
    call SetUnitPositionLoc( GetAttacker(), GetUnitLoc(udg_PlayerShip[GetConvertedPlayerId(GetOwningPlayer(GetAttacker()))]) )
endfunction

//===========================================================================
function InitTrig_Weapon_Move_3 takes nothing returns nothing
    set gg_trg_Weapon_Move_3 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Weapon_Move_3, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Weapon_Move_3, Condition( function Trig_Weapon_Move_3_Conditions ) )
    call TriggerAddAction( gg_trg_Weapon_Move_3, function Trig_Weapon_Move_3_Actions )
endfunction


So it turns out that he has three triggers, Weapon Move 1, 2 and 3.
Let me explain them one by one:

Weapon Move 1 utilizes a periodic event, occurring every 2 seconds. The trigger action is: Loop through all players, and move every weapon (dummy unit with no model) in the PlayerShip_Control[i] unit group array to the ship of the player. ("i" is the player number)
Code: Select all
//===========================================================================
// Trigger: Weapon Move 1
//===========================================================================
function Trig_Weapon_Move_1_Func001A takes nothing returns nothing
    call SetUnitPositionLoc( udg_PlayerShip_Control[GetConvertedPlayerId(GetEnumPlayer())], GetUnitLoc(udg_PlayerShip[GetConvertedPlayerId(GetEnumPlayer())]) )
endfunction

function Trig_Weapon_Move_1_Actions takes nothing returns nothing
    call ForForce( GetPlayersAll(), function Trig_Weapon_Move_1_Func001A )
endfunction

//===========================================================================
function InitTrig_Weapon_Move_1 takes nothing returns nothing
    set gg_trg_Weapon_Move_1 = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Weapon_Move_1, 2.00 )
    call TriggerAddAction( gg_trg_Weapon_Move_1, function Trig_Weapon_Move_1_Actions )
endfunction


Weapon Move 2 is not important. It happens when any unit is attacked. This causes a very little lag spike during battles :) 'u00P' is the code for a custom unit called "Control". I'm too lazy to check what it is or what it does, but I think you will know. The trigger only runs if that Control unit is the attacker. The action is basically this: Spread out every cannon under the ship (polar projection by RAND(0,128) pixels towards/facing RAND(0,360) degrees, then issue an attack order against whoever the attacker was/is.)
Code: Select all
//===========================================================================
// Trigger: Weapon Move 2
//===========================================================================
function Trig_Weapon_Move_2_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetAttacker()) == 'u00P' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Weapon_Move_2_Func001A takes nothing returns nothing
    call SetUnitPositionLoc( GetEnumUnit(), PolarProjectionBJ(GetUnitLoc(udg_PlayerShip[GetConvertedPlayerId(GetOwningPlayer(GetAttacker()))]), GetRandomReal(0.00, 128.00), GetRandomReal(0.01, 360.00)) )
    call IssueTargetOrderBJ( GetEnumUnit(), "attack", udg_PlayerShip_Target[GetConvertedPlayerId(GetOwningPlayer(GetAttacker()))] )
endfunction

function Trig_Weapon_Move_2_Actions takes nothing returns nothing
    call ForGroupBJ( udg_PlayerShip_Cannons[GetConvertedPlayerId(GetOwningPlayer(GetAttacker()))], function Trig_Weapon_Move_2_Func001A )
endfunction

//===========================================================================
function InitTrig_Weapon_Move_2 takes nothing returns nothing
    set gg_trg_Weapon_Move_2 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Weapon_Move_2, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Weapon_Move_2, Condition( function Trig_Weapon_Move_2_Conditions ) )
    call TriggerAddAction( gg_trg_Weapon_Move_2, function Trig_Weapon_Move_2_Actions )
endfunction


Weapon Move 3 is not important either. It checks for Ancient unit type (which probably means "this is a ship" or "this is a dummy weapon") and then if the two whatevers are close enough to each other (within 256 pixels) then moves them on top of each other. (I would like to express my confusion about this trigger: WTF! Thank you.)
Code: Select all
//===========================================================================
// Trigger: Weapon Move 3
//===========================================================================
function Trig_Weapon_Move_3_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetAttacker(), UNIT_TYPE_ANCIENT) == true ) ) then
        return false
    endif
    if ( not ( DistanceBetweenPoints(GetUnitLoc(GetAttacker()), GetUnitLoc(udg_PlayerShip[GetConvertedPlayerId(GetOwningPlayer(GetAttacker()))])) > 256.00 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Weapon_Move_3_Actions takes nothing returns nothing
    call SetUnitPositionLoc( GetAttacker(), GetUnitLoc(udg_PlayerShip[GetConvertedPlayerId(GetOwningPlayer(GetAttacker()))]) )
endfunction

//===========================================================================
function InitTrig_Weapon_Move_3 takes nothing returns nothing
    set gg_trg_Weapon_Move_3 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Weapon_Move_3, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Weapon_Move_3, Condition( function Trig_Weapon_Move_3_Conditions ) )
    call TriggerAddAction( gg_trg_Weapon_Move_3, function Trig_Weapon_Move_3_Actions )
endfunction
Unprotecting is fun :) I'm glad the JASS code wasn't obfuscated, because that'd have been a nightmare to read. If you have any questions or know what "Control" is, post!

--3ICE
Last edited by 3ICE on Sun May 24, 2009 3:20 pm, edited 3 times in total.
Reason: Updated again :)
ImageImageImageImageImage
Image
ImageImage
User avatar
3ICE
Admin
 
Posts: 2359
Joined: Sat Mar 01, 2008 11:34 pm
Location: Hungary
Realm: US East
Account: 3ICE
Clan: 3ICE

Re: Bships Code Error

New postby ikillforeyou on Mon May 25, 2009 11:30 am

Wow, thats all i ever needed, i think i know what 2 does... in the game when you order your ship to attack another ship it makes all your cannons attack that ship if they are able to. On a diff note, is there a way i can make my ships have the builder, non ato attk classification? Also, is there somthing i can do to find the highest integer in an array of 7 like If Integer[1] < Integer [2] Then.. Else... and so on? because having 14 if/then/else's would be laggy. Thanks! again. good job, i can never find the code that i'm looking for in deprocted maps. You use xdep right?


and i mean by that is like Get highest value of integers then return highest. <i would prefer to have it in gui, but jass would work too if you cant manage it
Last edited by ikillforeyou on Mon May 25, 2009 3:48 pm, edited 1 time in total.
ikillforeyou
 
Posts: 30
Joined: Sat Nov 22, 2008 4:10 pm

Re: Bships Code Error

New postby 3ICE on Mon May 25, 2009 11:48 am

ikillforeyounon ato attk
Oyh ess ai kne spkae stidup eglnish awsh lle!

Please start using a spell checker to lower the amount of mistakes you make when posting. If you don't know how to get one, ask google. It is very easy. And the user interface is very logical and lightweight: soliddocuments.com/images/blog_spell_check_firefox_2.png You right click the underlined misspelling and select the correction. (Or add it to the dictionary, which is basically a list of words that you prefer to misspell. Things like omg roflmao lol etc are underlined at first, but after you added them to your dictionary, the spell checker will simply ignore them.) By the way even IE has a spell checker, so it is not just for firefox.

ikillforeyoufind the highest integer in an array of 7
Use a loop: Use a loop:
t_set MaxValue=0
t_set i=0 //Start at 1 not 0 if you don't know how to use the first index in arrays (first index is Arr[0]).
t_act Loop Starts
t_all Exit when i>7 //Put the size of your array here.
t_if If (Array[i] > MaxValue) then set MaxValue = Array[i]
t_set i=i+1
t_act Loop ends
t_com ---- MaxValue is now equal to the highest number in the array. ----
(This is unusable PseudoJassGuiCode, but the idea is presented very clearly so you can make your own function now.)

ikillforeyouYou use xdep right?
Sometimes yes, but not for this map. Here I just extracted the war3map.j file into my programmer's notepad.
ImageImageImageImageImage
Image
ImageImage
User avatar
3ICE
Admin
 
Posts: 2359
Joined: Sat Mar 01, 2008 11:34 pm
Location: Hungary
Realm: US East
Account: 3ICE
Clan: 3ICE

Re: Bships Code Error

New postby ikillforeyou on Mon May 25, 2009 3:58 pm

K, so i have a timerwindow, and a dialog button array, when you press a dialog button cooresponding to an array sized 7 it sets the integer +1 i want it to get the highest number, and then return the number of the integer, starting at 1 sorta like this really bad jass i just made :P
Spoiler:
Code: Select all
Local timerwindow Local timer
Local integer I
Local integer W
Local timer expires <Local timer>
Get highest integer value Return <I>
Get which integer <I> Return <W>
If W = 1 then run Triggstr1 else do nothing
If W = 2 then run Triggstr2 else do nothing
If W = 3 then run Triggstr3 else do nothing


The real problem is i cant figure out how to get the integer number of the returned integer, is this the function i'm looking for? GetIntegerGameState??

would this work?

Spoiler:
Code: Select all
Gethighestintegervalue
    Events
        Time - Vote_Timer expires
    Conditions
    Actions
        For each (Integer A) from 1 to 7, do (Actions)
            Loop - Actions
                If (IGametypevotecount[(Integer A)] Greater than Highest_VotecountArray) then do (Set Highest_VotecountArray = (Integer A)) else do (Do nothing)
        If (Highest_VotecountArray Equal to 1) then do (Trigger - Run ABuff <gen> (ignoring conditions)) else do (Do nothing)
ikillforeyou
 
Posts: 30
Joined: Sat Nov 22, 2008 4:10 pm

Re: Bships Code Error

New postby 3ICE on Mon May 25, 2009 4:40 pm

No, GetIntegerGameState has nothing to do with anything mentioned in this thread.
And I'm sorry, but the trigger you posted is wrong. It does not work.
ImageImageImageImageImage
Image
ImageImage
User avatar
3ICE
Admin
 
Posts: 2359
Joined: Sat Mar 01, 2008 11:34 pm
Location: Hungary
Realm: US East
Account: 3ICE
Clan: 3ICE

Re: Bships Code Error

New postby ikillforeyou on Mon May 25, 2009 6:14 pm

i was just asking, and i asked if it did have anything with it, no need to scold me, anyhow, i just figured out how to do it in gui, with ALOT of triggers, here's what i came up with
Spoiler:

Gethighestintegervalue
Events
Time - Vote_Timer expires
Conditions
Actions
For each (Integer A) from 1 to 7, do (Actions)
Loop - Actions
If (IGametypevotecount[(Integer A)] Greater than Highest_VotecountArray) then do (Set Highest_VotecountArray = (Integer A)) else do (Do nothing)
-------- --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Highest_VotecountArray Equal to 1
Then - Actions
Game - Display to (All players) the text: Normal mode has bee...
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Highest_VotecountArray Equal to 2
Then - Actions
Trigger - Run Notrade <gen> (ignoring conditions)
Game - Display to (All players) the text: No trader mode has ...
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Highest_VotecountArray Equal to 3
Then - Actions
Game - Display to (All players) the text: No super ships mode...
Trigger - Run Nosuper <gen> (ignoring conditions)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Highest_VotecountArray Equal to 4
Then - Actions
Game - Display to (All players) the text: Accelerated mode ha...
Trigger - Run Accl <gen> (ignoring conditions)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Highest_VotecountArray Equal to 5
Then - Actions
Game - Display to (All players) the text: Accelerated No trad...
Trigger - Run Notrade <gen> (ignoring conditions)
Trigger - Run Accl <gen> (ignoring conditions)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Highest_VotecountArray Equal to 6
Then - Actions
Game - Display to (All players) the text: No super ships/trad...
Trigger - Run Notrade <gen> (ignoring conditions)
Trigger - Run Accl <gen> (ignoring conditions)
Else - Actions


With help from you, that idea was very important to my map. I will credit you, is there any specific message you want displayed? like Go to www.3ice.hu for all you warcraft help! Go there now!?

PS: why did you say that the trigger was wrong? the 2nd trigger worked... :D
ikillforeyou
 
Posts: 30
Joined: Sat Nov 22, 2008 4:10 pm

Re: Bships Code Error

New postby 3ICE on Mon May 25, 2009 6:47 pm

Well the code you posted above does not work, because there is a serious error in it, which completely breaks the functionality.
Simplified version yours:
Code: Select all
If (Arr[i] > MaxValue) then Set MaxValue = i
Simplified version fixed:
Code: Select all
If (Arr[i] > MaxValue) then Set MaxValue = Arr[i]
As you can see, the mistake was very small, but also very important to be fixed as I will show below.

Case study:
Arr[1]=2
Arr[2]=5
Arr[3]=107
Arr[4]=6
Arr[5]=5
Arr[6]=1
Arr[7]=2

Your function would think that Arr[5]=5 is the highest, because:
If (Arr[1]=2 > 0) then Set MaxValue = i=1 (MaxValue changed to i = 1)
If (Arr[2]=5 > 1) then Set MaxValue = i=2 (MaxValue changed to i = 2)
If (Arr[3]=107 > 2) then Set MaxValue = i=3 (MaxValue changed to i = 3)
If (Arr[4]=6 > 3) then Set MaxValue = i=4 (MaxValue changed to i = 4)
If (Arr[5]=5 > 4) then Set MaxValue = i=5 (MaxValue changed to i = 5)
If (Arr[6]=1 > 5) then Set MaxValue = i=6 (MaxValue stays at 5)
If (Arr[7]=2 > 5) then Set MaxValue = i=7 (MaxValue stays at 5)

But clearly, Arr[3]=107 is a lot higher than Arr[5]=5. Your function mixes up array indexes with array values.

p.s.: There are two ways your code can be fixed, the other solution being:
Code: Select all
If (Arr[i] > Arr[MaxValue]) then Set MaxValue = i

EDIT: I think you should use this second fix, as your "ALOT" of triggers (which you should have spelled as "a lot" by the way) use the Array indexes (i in JASS or (Index A) for GUI) in the if conditions.
ImageImageImageImageImage
Image
ImageImage
User avatar
3ICE
Admin
 
Posts: 2359
Joined: Sat Mar 01, 2008 11:34 pm
Location: Hungary
Realm: US East
Account: 3ICE
Clan: 3ICE

Re: Bships Code Error

New postby 3ICE on Mon May 25, 2009 6:59 pm

I edited my above post like ten times so it is time to stop editing and make a doublepost instead. (Which is against the rules, but whatever, I'm the admin :P)

How about dropping this whole array magic and providing usable text commands for the host instead? People will want two or more modes together anyway, like no trader and no super ships. (EDIT: I understand that vote option 7 does just that, but it is currently broken, turning on accl mode instead.)

p.s.: Most maps with voting go like this:
Host: Vote xy mode or I leave and ban everyone who didn't vote xy!
Host has voted xy
Player2 has voted xy.
Player3 has voted zz.
Player4 has voted zz.
Player 5 has voted zz.
Game message: Mode zz has been selected! (2 xy votes against 3 zz votes.)
Host: Player3, Player4 and Player5 banned.
Host has left the game!
ImageImageImageImageImage
Image
ImageImage
User avatar
3ICE
Admin
 
Posts: 2359
Joined: Sat Mar 01, 2008 11:34 pm
Location: Hungary
Realm: US East
Account: 3ICE
Clan: 3ICE

PreviousNext

Return to HELP



Who is online

Users browsing this forum: Google [Bot] and 24 guests