Simple Sum problem with jass

exge

New Member
Reaction score
15
im just starting JASS and i ran into problems even with a simple script like this :banghead: :banghead: :banghead: :banghead: :banghead:

Code:
function Trig_SumOfInt_Actions takes nothing returns integer
local integer firstNum
    local integer secondNum
    local integer sum = firstNum + secondNum
return sum
   
endfunction

function Trig_ShowSum takes integer sum_Actions returns string
    call DisplayTextToForce(GetPlayersAll(),"sum is " + sum)
endfunction

//===========================================================================
function InitTrig_SumOfInt takes nothing returns nothing
    set gg_trg_SumOfInt = CreateTrigger(  )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_SumOfInt, Player(0) )
    call TriggerAddAction( gg_trg_SumOfInt, function Trig_SumOfInt_Actions )
endfunction


I know this code has no real use in WE but i want to know why doesnt it compile
 

SFilip

Gone but not forgotten
Reaction score
634
this code is confusing. first of all trigger actions can't take anything.
second it seems that you never used Trig_ShowSum.
it seems Trig_ShowSum is supposed to return a string, but never does - you just call a function in it. also you never defined variable sum in it, the one it should take is called sum_Actions for you.
besides...
Code:
local integer firstNum
    local integer secondNum
    local integer sum = firstNum + secondNum
these numbers aren't set...it will probably just return 0.
 

exge

New Member
Reaction score
15
hmm .. well .. ok then ..... this is my 2nd script , 1st being the classic hello world ... can you show me how to fix this assume that the 2 ints have values
 

Chocobo

White-Flower
Reaction score
409
Code:
function Trig_SumOfInt_Actions takes integer a, takes integer b returns integer
local integer firstNum = a
    local integer secondNum = b
    local integer sum = firstNum + secondNum
return sum
   
endfunction

To use it : Trig_SumOfInt_Actions( the integer a, the intger b)
Example : Trig_SumOfInt_Actions( 1, 3)
Returns : 4
 

SFilip

Gone but not forgotten
Reaction score
634
Chocobo said:
Code:
function Trig_SumOfInt_Actions takes integer a, takes integer b returns integer
local integer firstNum = a
    local integer secondNum = b
    local integer sum = firstNum + secondNum
return sum
   
endfunction

To use it : Trig_SumOfInt_Actions( the integer a, the intger b)
Example : Trig_SumOfInt_Actions( 1, 3)
Returns : 4
can be simply...
Code:
function Trig_SumOfInt_Actions takes integer a, takes integer b returns integer
    return a + b   
endfunction
 

Chocobo

White-Flower
Reaction score
409
SFilip said:
can be simply...
Code:
function Trig_SumOfInt_Actions takes integer a, takes integer b returns integer
    return a + b   
endfunction

I would say Integer to String because it is a message.

Code:
function Trig_SumOfInt_Actions takes integer a, takes integer b returns [B]string[/B]
    return I2S(a + b )
endfunction

Edit : 0 Reputation member gives 1 Reputation point?
 

SFilip

Gone but not forgotten
Reaction score
634
> Edit : 0 Reputation member gives 1 Reputation point?
yeah
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
While on the subject of testing, locals and weird functions:

Assuming the following trigger:
Code:
TryMe
    Events
        Player - Player 1 (Red) skips a cinematic sequence
    Conditions
    Actions
        Custom script:   call TryMe()

and this function:
Code:
function TryMe takes nothing returns nothing
    local integer a = 0
    local integer b = 0
    local integer c = 1
    local integer count = 0

    loop
        set count = count + 1
        set a = b
        set b = c
        set c = a + b
        exitwhen c < a
    endloop

    call DisplayTextToForce( GetPlayersAll(), "Result: " + I2S(count))
endfunction

Would this function stop? Or run an endless loop, before it hits the trigger execution time limit?

In case it would finish, what result do you expect? What do you get?


Think about it first, before trying it if you want or need to... :p
 

exge

New Member
Reaction score
15
SFilip said:
> Edit : 0 Reputation member gives 1 Reputation point?
yeah

is it ? i didn't know that .. lol
i have 3 rep but its not said ....
o well .. thats life
 
D

dArKzEr0

Guest
Nice one Ace. I'm guessing it loops until the maximum value for an integer is reached, then c become negative and less than a?

-darkz

Edit://
I just tested it in java with the following program:
Code:
public class integers
{
    public static void main (String[ ] args)
    {
        int a=0, b=0, c=1, count=0;
        do
        {
            a=b; b=c; c=a+b;
            count++;
            if(count%5==1)
            System.out.println("a = "+a+"; b = "+b+"; c = "+c+"; count = "+ count);
        }
        while(c>a);
        System.out.println("final count = "+ count);
    }
}
And got:
a = 0; b = 1; c = 1; count = 1
a = 5; b = 8; c = 13; count = 6
a = 55; b = 89; c = 144; count = 11
a = 610; b = 987; c = 1597; count = 16
a = 6765; b = 10946; c = 17711; count = 21
a = 75025; b = 121393; c = 196418; count = 26
a = 832040; b = 1346269; c = 2178309; count = 31
a = 9227465; b = 14930352; c = 24157817; count = 36
a = 102334155; b = 165580141; c = 267914296; count = 41
a = 1134903170; b = 1836311903; c = -1323752223; count = 46
final count = 46
Is it the same for JASS?
 

SFilip

Gone but not forgotten
Reaction score
634
Chocobo said:
Sometimes with 0 reputation people, they +rep me but I gain 0 rep points ^^

Edit : There is people with 0 reputation who has red boxes, green boxes, or grey boxes? Is it normal?
only the ones with a gray box actually have 0 rep. people with green boxes have reputation lower than 5 (since the first "title" is 5+ i think) and people with red boxes have -1 reputation (since the first negative title is -2).
 

Chocobo

White-Flower
Reaction score
409
SFilip said:
only the ones with a gray box actually have 0 rep. people with green boxes have reputation lower than 5 (since the first "title" is 5+ i think) and people with red boxes have -1 reputation (since the first negative title is -2).

Some of them have 0 rep and have red/green boxes. (<whatever> has zero reputation)
 

exge

New Member
Reaction score
15
i did the code in java too .. :D
looks like another java programmer .... btw do you know jass, and if so, did knowing java help ??
i just checked , now i know why, iqchicken gave my -rep for NO Reason ...
Code:
 no reason, just like you gave me...

although he nv posted in my threads ??? :nuts: :nuts:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top