• 🏆 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!

[Trigger] Question about custom script involving libraries and structs

Status
Not open for further replies.
I'd like to learn how to access vjass structs and libraries through gui's custom script.

JASS:
library Sound requires Table
    private struct slop
        string snd
    endstruct
   
    struct Sound
        private static HandleTable preloadDB
       
        private static method preloadAfter takes nothing returns nothing
            local timer time=GetExpiredTimer()
            local slop s=preloadDB[time]
            local sound sd=CreateSound(s.snd,false,false,false,12700,12700,"")
            call SetSoundVolume(sd,1)
            call StartSound(sd)
            call KillSoundWhenDone(sd)
            call s.destroy()
            set sd=null
            call DestroyTimer(time)
            set time=null
        endmethod
       
        public static method preload takes string str returns nothing
            local timer time=CreateTimer()
            local slop s=slop.create()
            set s.snd=str
            set preloadDB[time]=s
            call TimerStart(time,.01,false,function thistype.preloadAfter)
            set time=null
        endmethod
       
        public static method play3D takes string str, real pitch, real x, real y, real z returns nothing
            local sound s = CreateSound(str,false,true,true,12700,12700,"")
            call SetSoundPosition(s,x,y,z)
            call SetSoundVolume(s,127)
            call SetSoundPitch(s,pitch)
            call StartSound(s)
            call KillSoundWhenDone(s)
            set s = null
        endmethod
       
        public static method playForPlayer takes string str, real pitch, player who returns nothing
            local sound s = CreateSound(str,false,false,false,12700,12700,"")
            if GetLocalPlayer()==who then
                call SetSoundVolume(s,127)
            else
                call SetSoundVolume(s,0)
            endif
            call SetSoundPitch(s,pitch)
            call StartSound(s)
            call KillSoundWhenDone(s)
            set s = null
        endmethod
       
        public static method play takes string str, real pitch, integer vol returns nothing
            local sound s = CreateSound(str,false,false,false,12700,12700,"")
            call SetSoundVolume(s,vol)
            call SetSoundPitch(s,pitch)
            call StartSound(s)
            call KillSoundWhenDone(s)
            set s = null
        endmethod
       
        private static method onInit takes nothing returns nothing
            set preloadDB=HandleTable.create()
        endmethod
    endstruct
endlibrary
I know its useless and pointless but this'll feel better instead of the alternative being open up a vjass system's .j file to extract its jass and then rename variables one by one.

Maybe I'll learn how to use proper code at this rate. :peasant-work-work:
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
I remember there being a desync problem with
JASS:
public static method playForPlayer takes string str, real pitch, player who returns nothing
for the current version of Warcraft 3. I think you had to locally call StartSound instead to fix the issue.

Regarding your question:
  • Custom Script: call Sound.play(udg_YourStringVariable, somePitch, someVolume)
 
What about SEE : Simple Entity Engine 2.4 ? It uses even further advanced vjass syntax I don't have a clue on how to fit it into custom script.

I saw in DelFX - Delayed Effects 1.4.2 that you can sort of bridge vjass to jass with duplicate function calls similar to how gui/BJ's are done.
JASS:
    function CreateDelayedEffectTarget takes string path, widget target, string attachmentpoint, real delay, real timeout returns nothing
        call DELFX.Create(path, true, target, attachmentpoint, 0, 0, 0, delay, timeout)
    endfunction

Which gimli_2 gave me a nice example of without needing the extra function call, but looking into some vjass code it doesn't seem that easy when it uses structs and methods with no normal jass access and custom local variables aka local entity e.
 
Level 39
Joined
Feb 27, 2007
Messages
5,015
It's literally exactly the same. You just call the methods or set struct members line-by line.

SEE has an addon library (SEEdatalib) in which you are supposed to define your map's types of entities, so you will have to set that up. Duplicate the default ball struct and replace/change whatever makes sense to you; all of the fields you're allowed to define (and methods you're allowed to overwrite) can be seen in the SEEentityData addon library.

You can either define local variables at the top of GUI tiggers or create a globals block inside the SEEdatalib to define some global variables and just reuse those in every trigger where you need them. These will not have the udg_ prefix added automatically like Variable Editor variables do. You are welcome to add it yourself if you want or just not use a mostly unnecessary prefix.

Refer to the example map's "initialization" trigger to see how to create an manipulate entities (since SEE's documentation doesn't include any specific examples): set e = entity.create(ball.create(), Player(0), TEXT_X - TEXT_SEGMENT_OFFSET*i, TEXT_Y - 2.0*TEXT_SEGMENT_OFFSET*bj_PI, 1200.0, 0.0). Refer to the Member List and Method List documentation to see the what and how of interacting with entities you create.
 
Edit: Still curious about that syntax error however I found something better [Snippet] TimedHandles and works normally as expected when imported.

Trying to find the old table by vexorian was a pain... Managed to find it off of old vjass systems in spell section.
However this is what I keep running into when trying some specific advanced vjass code.
hmmsyntax.jpg
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
5,015
create shouldn't be capitalized. No the method actually has a capital C, which IMO is dumb. The reason is: DELFX is a private struct. If you want to be able to use it that way (instead of the function call notation shown in the system API) you could remove the word "private" from its struct definition.
 
create shouldn't be capitalized. No the method actually has a capital C, which IMO is dumb. The reason is: DELFX is a private struct. If you want to be able to use it that way (instead of the function call notation shown in the system API) you could remove the word "private" from its struct definition.
Is it just removing private off of each struct/method to be able to call it normally in jass/custom-script? I tried reading that link of vjass documentation you posted but its just a giant wall of spam to me.
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
public (or NOT private, public is default): can be accessed from anywhere
private: private methods can only be called from inside the struct, private structs probably can only be called from inside the same library, but i am not sure.

You can add me on discord if you want to get into jass. GIMLI_2 #5123
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
5,015
public (or NOT private, public is default)
You're slightly incorrect. Public requires you to use any relevant scope prefixes to refer to the data structure. Not writing either puts it in the global scope.
JASS:
library SomeLib
  struct Thing
    //...
  endstruct

  public struct Object
    //...
  endstruct

  private struct Foo
    //...
  endstruct

  scope Inward
    public struct Bar
      //...
    endstruct
  endscope
endlibrary

//from outside the library:
call Thing.create()
call SomeLib_Object.create()
call Foo.create() //syntax error, Foo not defined in current scope
call SomeLib_Inward_Bar.create()
 
Level 39
Joined
Feb 27, 2007
Messages
5,015
Private is for making sure things can't be touched by code that isn't supposed to touch them. And for not having to worry about object/variable name conflicts (though the public keyword is also a way to avoid such namespace issues).
So then that means removing or replacing private with public should solve any vjass problem?
No, reread my reply and see the difference between accessing the public struct and the <nothing> struct.
 
Last edited:
Status
Not open for further replies.
Top