Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on and when in functions does not work #746

Closed
abenkovskii opened this issue Apr 7, 2015 · 4 comments
Closed

on and when in functions does not work #746

abenkovskii opened this issue Apr 7, 2015 · 4 comments
Assignees
Labels
bug Weird outcome is probably not what the mod programmer expected.

Comments

@abenkovskii
Copy link
Contributor

this code:

declare function test1 {
  when abort then {
    print "test1_trigger".
  }
  wait 10.
}
test1().

and this code:

declare function test1 {
  on abort {
    print "test1_trigger".
  }
  wait 10.
}
test1().

Both in the console and in the file print nothing. No matter how many times I hit the "abort" button
However this code:

on abort {
  print "test1_trigger".
}
wait 10.

prints "test1_trigger"
and this code:

when abort then {
  print "test1_trigger".
}
wait 10.

Both in the console and in the file print "test1_trigger" when I press the "abort" button.

@erendrake
Copy link
Member

this is likely related to the closure work @Dunbaratu is doing?

@Dunbaratu
Copy link
Member

Not sure - I'll have to have a look at things.

@abenkovskii
Copy link
Contributor Author

code:

// file bug2.ks
declare function test1 {
  when true then {
    print "test1_trigger".
  }
  wait 10.
}
test1().
set a to 1/0.

log:

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)

kOS: At bug2 on 1, line 8
set a to 1/0.
          ^

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)

System.DivideByZeroException: Division by zero

  at kOS.Safe.Compilation.CalculatorIntInt.Divide (System.Object argument1, System.Object argument2) [0x00000] in <filename unknown>:0 

  at kOS.Safe.Compilation.OpcodeMathDivide.ExecuteCalculation (kOS.Safe.Compilation.Calculator calc) [0x00000] in <filename unknown>:0 

  at kOS.Safe.Compilation.BinaryOpcode.Execute (ICpu cpu) [0x00000] in <filename unknown>:0 

  at kOS.Execution.CPU.ExecuteInstruction (kOS.Execution.ProgramContext context) [0x00000] in <filename unknown>:0 

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)

Code Fragment

File                 Line:Col IP   opcode operand
----                 ----:--- ---- --------------------- 
                        0:0   0000 jump 7 
1/bug2                  1:24  0001 pushscope 1 0 
1/bug2                  5:8   0002 push 10 
1/bug2                  5:8   0003 wait 
1/bug2                  6:1   0004 popscope 1 
1/bug2                  6:1   0005 push 0 
1/bug2                  6:1   0006 return 
1/bug2                  1:1   0007 push $test1* 
1/bug2                  1:1   0008 push 1 
1/bug2                  1:1   0009 store 
1/bug2                  7:6   0010 push $<argstart> 
1/bug2                  7:6   0011 call $test1* 
1/bug2                  7:6   0012 pop 
1/bug2                  8:5   0013 push $a 
1/bug2                  8:10  0014 push 1 
1/bug2                  8:12  0015 push 0 
1/bug2                  8:11  0016 div <<--INSTRUCTION POINTER--
1/bug2                  8:11  0017 store 
                        0:0   0018 EOP 

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)

kOS: Stack dump: stackPointer = 1
001 SP-> $a
000      0

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)

kOS: Popping context 2

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)

kOS: Removed Context File                 Line:Col IP   opcode operand

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)

kOS: Deleting 0 pointers and restoring 1 pointers

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)

kOS: New current context File                 Line:Col IP   opcode operand

(Filename: C:/BuildAgent/work/d63dfc6385190b60/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 49)

@Dunbaratu
Copy link
Member

According to that log, the WHEN isn't just being compiled wrongly. It's never even being compiled at all. It's entirely missing from the ML program, giving output that would be identical to what you would get if the WHEN was entirely deleted from the script.

Weird.

@Dunbaratu Dunbaratu added this to the v0.17.0 Punchlist milestone Apr 9, 2015
@Dunbaratu Dunbaratu self-assigned this Apr 9, 2015
@Dunbaratu Dunbaratu added the bug Weird outcome is probably not what the mod programmer expected. label Apr 9, 2015
Dunbaratu added a commit to Dunbaratu/KOS-1 that referenced this issue Apr 9, 2015
…se now.

Function bodies previously didn't get preparsed for triggers
properly.  Now it recurses down into themto ensure it finds
the triggers inside.  This fixes both the problems
because RUN and WHEN are both in need of a preprocess pass to
work properly, and it was the lack of that preprocess pass that
was causing the problem in both these cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Weird outcome is probably not what the mod programmer expected.
Projects
None yet
Development

No branches or pull requests

3 participants