• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Some JASS Confusion (Function Questions)

Status
Not open for further replies.
Level 6
Joined
Jan 15, 2005
Messages
188
I've been using JASS alot lately, but I'm confused on how a few things work... because I'm tired of using BJ's when I shouldn't. Here's my problems:

1. Player(integer) - What player is what? Is Player(0) red? Is Player(12) brown? I'm not sure how this works, exactly.
2. MultiboardGetItem(multiboard, integer, integer) - I set a multiboarditem to this, and it seems that rows are a little messed up. If it were MultiboardGetItem(mb, 1, 1), wouldn't that be the "O" on this 3x3 multiboard?:
Code:
|-----|
|O|X|X|
|-|-|-|
|X|X|X|
|-|-|-|
|X|X|X|
|-----|
I thought it'd be column 1, row 1, like the multiboard in BJ produces. I'm really confused on how this works, and if I should try the mbitems or keep sticking with BJ for multiboards.
3. Referring to #2, has anyone had the experience of a multiboard spreading 100% across the screen with no text or anything to be implied? If so, does anyone know why it happens? I can provide a screenshot if this question is confusing.
4. PolledWait(real) and TriggerSleepAction(real) - Are these two things any different? Is PolledWait more efficient than TriggerSleepAction? I looked at the PolledWait function and it looked extremely long and bad, but I'm not sure if it has any advantage over TriggerSleepAction.

Hopefully someone can answer my questions, and I will give rep to anyone who helps me. Thanks in advance.
 
Level 17
Joined
Apr 13, 2008
Messages
1,597
In GUI: Player 1 is RED.
In JASS: Player 0 is RED. It's because you index starting from 0 in programming languages.

Mb(1,1) in that multiboard is 'O'.
Keep sticking with the BJ function when it comes to multiboards. You can set items in one line instead of 32135 lines.

I understand your #3 problem, but I don't know what would cause it. I would say you have set your multiboard's size to huge. Please post triggers.

I'm a little tired of explaining the difference between Waits and PolledWaits. Please use the search function.
 
Level 6
Joined
Jan 15, 2005
Messages
188
emperor_d3st said:
In GUI: Player 1 is RED.
In JASS: Player 0 is RED. It's because you index starting from 0 in programming languages

Mb(1,1) in that multiboard is 'O'.
Keep sticking with the BJ function when it comes to multiboards. You can set items in one line instead of 32135 lines.
Thank you, that truly helps me a lot.

emperor_d3st said:
I understand your #3 problem, but I don't know what would cause it. I would say you have set your multiboard's size to huge. Please post triggers.
Well since I guess I'll just use BJ functions, this wont happen. I'm not sure what caused it, but I'm not going to dig deep into it because BJ functions work best for multiboards (as I understand it).

emperor_d3st said:
I'm a little tired of explaining the difference between Waits and PolledWaits. Please use the search function.
Sorry!

Rep added. =)
 
for multiboards don't use BJs, they just make you waste a lot of micro-operations, ALWAYS but always use natives in JASS.

I'll explain how Multiboards truely work.

JASS:
globals
        multiboard MS
endglobals

function Test takes nothing returns nothing
local multiboarditem mb
set MS = CreateMultiboard() //Creates the multiboard
call MultiboardSetRowCount(MS, 10) //Defines the number of Rows
call MultiboardSetColumnCount(MS, 1) //Defines the number of Columns
//Now lets say you want to edit an specific item
set mb = MultiboardGetItem(MS, 0, 0) //0 stands for first, this takes position row 1, column 1
//Here we are getting the item, it's an object inside the multiboard
call MultiboardSetItemValue(mb, "I'm teh Item") //We specify text value
call MultiboardSetItemIcon( mb, "ReplaceableTextures\\CommandButtons\\BTNOrbOfFire.blp" ) //We specify Icon
call MultiboardSetItemWidth(mb, 0.172) //we specify width, it's in percentage (take a value from 0 to 100 and divide it on 100)
call MultiboardSetItemStyle(mb,true,true) //specifies that icon and text are shown
//now we clear leaks
call MultiboardReleaseItem(mb)
//cleared
//Time to show our multiboard
call MultiboardDisplay(MS, true)
//If you want to display it to an specific player
//use "if GetLocalPlayer()== Your_Player then" and set the actions
//NOTE: Multiboard items are local code, you can display different values
//to different players using the same multiboard without desyncs.
endfunction

4th TriggerSleepAction sends the current thread to sleep, but has a limit; you can't send a thread to sleep for less than 0.12 seconds, polledWaits haven't this limitations. I suggest you to avoid using any of them and try to use timers + callbacks.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
MultiboardBJ:s are really ineffective. For each action you do for each call, you run a loop with index 0 and exitwhen 1...
A loop which is not needed unless you are typing the value for a row or a column in gui as "0".
I mean, look at it... You can do a waaaay better code using non-BJs
JASS:
function MultiboardSetItemWidthBJ takes multiboard mb, integer col, integer row, real width returns nothing
    local integer curRow = 0
    local integer curCol = 0
    local integer numRows = MultiboardGetRowCount(mb)
    local integer numCols = MultiboardGetColumnCount(mb)
    local multiboarditem mbitem = null

    // Loop over rows, using 1-based index
    loop
        set curRow = curRow + 1
        exitwhen curRow > numRows

        // Apply setting to the requested row, or all rows (if row is 0)
        if (row == 0 or row == curRow) then
            // Loop over columns, using 1-based index
            set curCol = 0
            loop
                set curCol = curCol + 1
                exitwhen curCol > numCols

                // Apply setting to the requested column, or all columns (if col is 0)
                if (col == 0 or col == curCol) then
                    set mbitem = MultiboardGetItem(mb, curRow - 1, curCol - 1)
                    call MultiboardSetItemWidth(mbitem, width/100.0)
                    call MultiboardReleaseItem(mbitem)
                endif
            endloop
        endif
    endloop
endfunction

A multiboard is just like Players starting on row 0 and column 0. Therefor if you are using jass:
native MultiboardGetItem takes multiboard lb, integer row, integer column returns multiboarditem

where the rows and columns start with the index 0,0.

The reason to your third problem could be that you have used the setWidth wrong.
In the function MultiboardSetItemWidthBJ takes multiboard mb, integer col, integer row, real width returns nothing

you find that it calls
call MultiboardSetItemWidth(mbitem, width/100.0)

Thus means when you don't use BJ the value is 0<width<1. Also, one single multiboard item shouldn't have the value 1. I don't know if there is a faster way, but try experimenting with it to make sure you get the proper size you want.

Polled wait are definately worser than Trigger Sleep Action due to the fact that you can use TSA instead of Polled Wait, since its much faster. (oups, messed up sentence there maybe...)
I dont know much more about it though.

xO I missed the two last posts due to this
 
Level 6
Joined
Jan 15, 2005
Messages
188
BlinkBoy said:
4th TriggerSleepAction sends the current thread to sleep, but has a limit; you can't send a thread to sleep for less than 0.12 seconds, polledWaits haven't this limitations.
Thank you so much - I couldn't find the answer in search. >(

BlinkBoy said:
I suggest you to avoid using any of them and try to use timers + callbacks.
Could you explain this a little more? How would it be used to effectively replace TriggerSleepAction or PolledWait?

Eccho said:
you find that it calls
JASS:
call MultiboardSetItemWidth(mbitem, width/100.0)
Wow, I completely missed that. Yes, that was most definitely the issue. I will now be able to use it effectively thanks to BlinkBoy and the finding of that problem! Thanks.

+Rep to both of you!
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Jass Manual said:
A trigger, used in a map script, is a callback; that is, it an event handler that is installed to execute when a particular event(s) occur.

Callbacks are used through handles. If you know HSAS or ABC, or CS handle vars it attaches a timer through a callback code, and then uses the timer when it expires to gain local handles and variables used by the previous function where the timer was started.

An example, I don't know the syntaxes though, but it should give ou a brief overwiev.
JASS:
function DoA takes nothing returns nothing
local timer t = CreateTimer()
local unit u = GetTriggerUnit()
call AttachUnit(t, u, "caster") //like I said I dont even know if this pure code exists, but something like that, depending on the system used.
call StartTimer(t, blabla, ...........)
endfunction

function ExpiredTimer takes nothing returns nothing //used in a trigger with an expiration event
local timer t = GetExpiredTimer()
local unit u = GetAttachedUnit(t, "caster")
// do something
endfunction

And yep, you should easily find more info about this like everywhere ^_^

Damn I write so slow... missed 2 posts again xO
 
Level 17
Joined
Apr 13, 2008
Messages
1,597
Originally Posted by BlinkBoy
4th TriggerSleepAction sends the current thread to sleep, but has a limit; you can't send a thread to sleep for less than 0.12 seconds, polledWaits haven't this limitations.
Sorry but this is incorrect information. I would elaborate on that but I'm in the middle of a game right now.

About multiboard BJs:
Some multiboard operations are totally fine as BJs, some not. The reason: you have to type less, spend much less time writing your code and takes up less map space. Sure, when you update your multiboard very frequently then you should consider using your own code instead.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Sorry but this is incorrect information. I would elaborate on that but I'm in the middle of a game right now.
It's around there, and it's rather random. It's closer to .20 or .27 seconds in practice.

Some multiboard operations are totally fine as BJs, some not. The reason: you have to type less, spend much less time writing your code and takes up less map space. Sure, when you update your multiboard very frequently then you should consider using your own code instead.
BJs take a few less lines of code, are way messier, and way slower. It's really not worth it.

All this junk about coding a multiboard natively being bad is, as I said, junk.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Some multiboard operations are totally fine as BJs, some not. The reason: you have to type less, spend much less time writing your code and takes up less map space. Sure, when you update your multiboard very frequently then you should consider using your own code instead.

I would rather say since they are so inefficient, why not take your time learning without using them, instead?
 
Status
Not open for further replies.
Top