• 🏆 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] texttags with localplayer

Status
Not open for further replies.
Level 6
Joined
Oct 23, 2011
Messages
182
after hearing that creating texttags with localplayer allows each player to have 100 texttags instead of a global stack, I started using it.

I have a few question though

1. After creating the texttag with GetLocalPlayer, do I have to use functions involving texttag within the local player block as well? or would it simply not matter? Do i have to destroy them in localplayer as well?

2. What happens if I use both non-localplayer texttags and localplayer texttags at the same time? i've done a few tests with a friend of mine, creating 60 localplayer texttags + 60 regular ones at same time

seems like the global stack is separate from each player's texttag stacks, but I don't know if this would cause desync and such
 
Level 6
Joined
Oct 23, 2011
Messages
182
Level 17
Joined
Apr 27, 2008
Messages
2,455
Well, creating/destroying textags in local blocks is fine, but that doesn't mean use any code in a local block is fine, you can't generally destroy/create handles, or open a new thread, or even set a different value for a global variable (if it's used in a global block later and in a way that will make different situations).

It's hard to explain cases which will make a desync, it's something you have to understand by yourself.
 
Level 6
Joined
Oct 23, 2011
Messages
182
Well, creating/destroying textags in local blocks is fine, but that doesn't mean use any code in a local block is fine, you can't generally destroy/create handles, or open a new thread, or even set a different value for a global variable (if it's used in a global block later and in a way that will make different situations).

It's hard to explain cases which will make a desync, it's something you have to understand by yourself.

Ah, I cannot set the value to global variable? I guess that's why :vw_sad:
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Ah, I cannot set the value to global variable? I guess that's why

No you can, but it depends how you use it later.

For example this will obviously make a descyn :

JASS:
globals
    integer I = 0
endglobals

if GetLocalPlayer() == Player(0) then
    set I = 1
endif

loop
exitwhen I == 0
set I = I-1
    call CreateUnit(...)
endloop

@Mag : wtf ?!
 
Level 6
Joined
Oct 23, 2011
Messages
182
So... would this cause desync?
I'm totally lost. Would this allow me to have 8191 instances per player? ......
so only local non-handle variables in local block?

I thought I knew a little about localplayer stuff, but now i'm starting to question my knowledge..

JASS:
struct Test

    texttag tt
    
    static method create takes player p returns thistype
        local thistype this
        
        if GetLocalPlayer() == p then
            set this = thistype.allocate()
            
            set .tt = CreateTextTag()
        endif
        
        return this
    endmethod
    
endstruct
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
You can create text tags asynchronously. The problem is all strings must be created synchronously. Thus you will have to make the string you are going to display via text tag synchronously before you asyncrhonously create the text tags.

I am not sure if setting a global to 2 different values will cause an OoS split for certain value types (like integer).

Locally and globally has nothing to do with this although I know locals do not need to be synchronous.
 
Level 6
Joined
Oct 23, 2011
Messages
182
You can create text tags asynchronously. The problem is all strings must be created synchronously. Thus you will have to make the string you are going to display via text tag synchronously before you asyncrhonously create the text tags.

I am not sure if setting a global to 2 different values will cause an OoS split for certain value types (like integer).

Locally and globally has nothing to do with this although I know locals do not need to be synchronous.

Is there some other way to create the string synchronously without createing the synchronous texttags first? like saving the string to a hashtable
I would like to try keep my system lightweight, instead of checking if the string was create synchronously or not
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
He means that :

JASS:
local string s = "your text"

if GetLocalPlayer(...
    // do stuff with s but not set it, read it
endif

But i still disagree, i've myself already used strings in local blocks, it didn't desycn, but well that wasn't in a real map though.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
I disagree, else local strings (depends the wc3 language installed) wouldn't work that much.
Localized (not local) strings are one of the most common causes of map splits I have found. A get player name opperation with an AI slot was causing a guy a lot of map splits last year.

Is there some other way to create the string synchronously without createing the synchronous texttags first?
Yes you allocate it before hand. If you use a finite set of constant strings you can even just allocate them all at once during map initialization. You can then use the string as a constant in any asynchronous block as it does not allocate a new string. The problem is unique strings asynchrnously which allocate a new string.

But i still disagree, i've myself already used strings in local blocks, it didn't desycn, but well that wasn't in a real map though.
The strings you used were already allocated. I know that use of the native to get a player's name has the potential to return an asynchrnous string and can easilly cause a OoS map split.
 
@Troll-Brain:

It's true. I think you can actually go beyond the 100-texttag per player limit using this.
Those in-game texttags like "miss" and "xxxx (critical strike)" can be pointed to using this trick. You can collect them and put them into a stack and
Profit! :D

The problem is all strings must be created synchronously

Actually, you don't have to do that to avoid desyncs, but-
wait a second...

JASS:
function bleh takes string s returns nothing
endfunction

local string s = "lol"
local string t

if GetLocalPlayer() == Player(0) then
    call bleh("bye")
endif

set t = "hi"

call BJDebugMsg(t)

If I were to do something like this, would Player 1 see "bye"?
 
Level 6
Joined
Oct 23, 2011
Messages
182
@Troll-Brain:

It's true. I think you can actually go beyond the 100-texttag per player limit using this.
Those in-game texttags like "miss" and "xxxx (critical strike)" can be pointed to using this trick. You can collect them and put them into a stack and
Profit! :D



Actually, you don't have to do that to avoid desyncs, but-
wait a second...

JASS:
function bleh takes string s returns nothing
endfunction

local string s = "lol"
local string t

if GetLocalPlayer() == Player(0) then
    call bleh("bye")
endif

set t = "hi"

call BJDebugMsg(t)

If I were to do something like this, would Player 1 see "bye"?

i see byehi
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
It's true. I think you can actually go beyond the 100-texttag per player limit using this.
Those in-game texttags like "miss" and "xxxx (critical strike)" can be pointed to using this trick. You can collect them and put them into a stack and Profit! :D
Too bad those are limited to 100 instances in the first place. This is why if you kill 100s of units at once you will not see the gold earned for all of them.

If I were to do something like this, would Player 1 see "bye"?
As those are string constants, they are probably loaded into the string table at map initialization so are all synchronous. You are mearly accessing one asynchronously. Only hi will be displayed as bleh does nothing (empty function).
 
Status
Not open for further replies.
Top