• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] Why don't I get thoes results? Help me!!

Status
Not open for further replies.
Level 2
Joined
Jun 12, 2016
Messages
11
I'm learning struct chapter from JassHelper Manual but it doesn't display any results nor answers and keeps show up some errors. This is too much annoying for me--

JASS:
struct pairpair
  pair x=0
  pair y=0
endstruct

function testpairs takes nothing returns nothing
local pairpair A=pairpair.create()
local pair x

  set A.x = pair.create()
  set A.y = pair.create()

  set x=A.y
  set A.y= pair_sum(A.x,A.y)

  call BJDebugMsg(I2S(  A.y.x )+" : "+I2S( A.y.y ))

  call A.x.destroy()
  call A.y.destroy()
  call A.destroy()
  call x.destroy()
endfunction

function Init_struct takes nothing returns nothing
  local trigger t = CreateTrigger()
  call TriggerRegisterTimerEventPeriodic(t, 2)
  call TriggerAddAction(t, function testpairs)
endfunction

this code has error like:
Untitled.png




I think there is no pair_sum function in the code when I after upload this thread.
JASS:
function pair_sum takes pair A, pair B returns pair
local pair C=pair.create()
  set C.x=A.x+B.x
  set C.y=A.y+B.y
return C
endfunction

Then, Where do I put that pair_sum function?
 
Last edited:
Make sure you declare the struct "pair" in your code, above pairpair. And yeah, it doesn't look like you have pair_sum.

Also, make sure Init_struct is set as an initializer at some point. I'll put it in a scope. Try the code below:
JASS:
scope TestPair initializer Init_struct

    struct pair
        integer x
        integer y
    endstruct

    struct pairpair
        pair x = 0
        pair y = 0
    endstruct

    function pair_sum takes pair A, pair B returns pair
        local pair C = pair.create()
        set C.x = A.x + B.x
        set C.y = A.y + B.y
        return C
    endfunction

    function testpairs takes nothing returns nothing
        local pairpair A =pairpair.create()
        local pair x

        set A.x = pair.create()
        set A.y = pair.create()

        set x =A.y
        set A.y = pair_sum(A.x, A.y)

        call BJDebugMsg(I2S( A.y.x )+" : "+I2S( A.y.y ))

        call A.x.destroy()
        call A.y.destroy()
        call A.destroy()
        call x.destroy()
    endfunction

    function Init_struct takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterTimerEventPeriodic(t, 2)
        call TriggerAddAction(t, function testpairs)
    endfunction

endscope
 
Level 2
Joined
Jun 12, 2016
Messages
11
I'm learning struct chapter from JassHelper Manual but it doesn't display any results nor answers and keeps show up some errors. This is too much annoying for me--

JASS:
struct pairpair
  pair x=0
  pair y=0
endstruct

function testpairs takes nothing returns nothing
local pairpair A=pairpair.create()
local pair x

  set A.x = pair.create()
  set A.y = pair.create()

  set x=A.y
  set A.y= pair_sum(A.x,A.y)

  call BJDebugMsg(I2S(  A.y.x )+" : "+I2S( A.y.y ))

  call A.x.destroy()
  call A.y.destroy()
  call A.destroy()
  call x.destroy()
endfunction

function Init_struct takes nothing returns nothing
  local trigger t = CreateTrigger()
  call TriggerRegisterTimerEventPeriodic(t, 2)
  call TriggerAddAction(t, function testpairs)
endfunction

this code has error like:
View attachment 241152


I think there is no pair_sum function in the code.

JASS:
function pair_sum takes pair A, pair B returns pair
local pair C=pair.create()
  set C.x=A.x+B.x
  set C.y=A.y+B.y
return C
endfunction

Then, Where do I put that pair_sum function?
Make sure you declare the struct "pair" in your code, above pairpair. And yeah, it doesn't look like you have pair_sum.

Also, make sure Init_struct is set as an initializer at some point. I'll put it in a scope. Try the code below:
JASS:
scope TestPair initializer Init_struct

    struct pair
        integer x
        integer y
    endstruct

    struct pairpair
        pair x = 0
        pair y = 0
    endstruct

    function pair_sum takes pair A, pair B returns pair
        local pair C = pair.create()
        set C.x = A.x + B.x
        set C.y = A.y + B.y
        return C
    endfunction

    function testpairs takes nothing returns nothing
        local pairpair A =pairpair.create()
        local pair x

        set A.x = pair.create()
        set A.y = pair.create()

        set x =A.y
        set A.y = pair_sum(A.x, A.y)

        call BJDebugMsg(I2S( A.y.x )+" : "+I2S( A.y.y ))

        call A.x.destroy()
        call A.y.destroy()
        call A.destroy()
        call x.destroy()
    endfunction

    function Init_struct takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterTimerEventPeriodic(t, 2)
        call TriggerAddAction(t, function testpairs)
    endfunction

endscope

Sorry for the delayed response and thank you again.

if you don't mind, can I ask one more question?


Cal.png


I built a function to find that ∠B of the corn shape, is this right function?

bj_RADTODEG*Atan2((Asin(this.h/this.l)), (Acos(this.r/this.l)))
 
Level 4
Joined
Sep 13, 2014
Messages
106
Probably not... you are taking distances, ratioing them, sin/cosing them which returns two angles, and then using these angles (in radians) as distances, and these distances you use to find an angle.

If that diagram is accurate, the function should be bj_RADTODEG*Atan2(this.h, this.r) (if you want it to return degrees)
 
Level 2
Joined
Jun 12, 2016
Messages
11
Probably not... you are taking distances, ratioing them, sin/cosing them which returns an angle, and then using this angle (in radians) as a distance, and these distances you use to find an angle.

If that diagram is accurate, the function should be bj_RADTODEG*Atan2(this.h, this.r) (if you want it to return degrees)

Thanks to reply ZerGreenOne, but what is 'return' in the function of jass? :/
 
Level 4
Joined
Sep 13, 2014
Messages
106
The return value of a function is the value that it acts as once it has finished execution. Like, for example, if you have Sin(Sin(45)), Sin 45 will return approximately 0.85090352453, and so the function will essentially be the same as Sin(0.85090352453). This will then evaluate and return a value, so overall, Sin(Sin 45) will return 0.75187640936.

Sin(Sin(45)) ------------------- // But Sin(45) = 0.85090352453
Sin(0.85090352453) -------- // But Sin(0.85090352453) = 0.75187640936
0.75187640936

The 'return' keyword in a function skips all the remaining steps and makes the function act as whatever the value of the function after the return is.

Code:
return 0 // This will make the function return the value 0
return Sin(45) // This will make the function return the value returned by the function Sin(45), which is equal to approximately 0.85090352453

And I don't literally mean "return degrees", I mean "return a value in degrees" as opposed to "return a value in radians"
 
Status
Not open for further replies.
Top