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

E2 does not recognize local variables inside events defined outside of them when included in another file #3224

Open
unknao opened this issue Dec 22, 2024 · 5 comments

Comments

@unknao
Copy link
Contributor

unknao commented Dec 22, 2024

I ran into a problem where an e2 that when isn't included works fine without warnings, but when included in a seperate e2 gives a nonsensical error.

The e2 in question:
{ACC259F3-37EF-43C4-B6B9-C6654E661C71}

The error when the file is included:
{A01B8BD9-CB00-4BD9-97BC-D163B171929D}

@unknao
Copy link
Contributor Author

unknao commented Dec 22, 2024

Here is the code in text form:

@inputs A D
@inputs [FL_Wheel #[Front left wheel slave]# FR_Wheel #[Front right wheel slave]# R_Wheel #[Rear wheel slave]# Base]:entity
@inputs Base2:entity #[Slave for rear wheels, if not using live axle suspension, wire the same as the base]#
@outputs Curve
@strict

Steering_Max = 35 #Maximum steering angle
Steering_Rate = 0.1 #How fast the steering angle changes
Steering_Rate_Max = 2.2 #Upper bound of how fast the steering angle can change

Gyro = 0
Gyro_Mul = 0

Wheel_Track = 83.007 #Distance between the wheels lengthwise
Wheel_Width = 68.125 / 2 #Distance between the wheels widthwise divided by 2

let Curve_Target = 90
Curve = 90

let N = Wheel_Track * tan(Curve)
let L = atan(Wheel_Track / (N - Wheel_Width))
let R = atan(Wheel_Track / (N + Wheel_Width))
let TickAdjust = 66 * tickInterval()

event tick(){
    Curve_Target = 90 - clamp((A - D) * Steering_Max + Gyro * Gyro_Mul, -Steering_Max, Steering_Max)
    if(Curve_Target != Curve){
        Curve += clamp((Curve_Target - Curve) * Steering_Rate, -Steering_Rate_Max, Steering_Rate_Max) * TickAdjust
        
        N = Wheel_Track * tan(Curve)
        L = atan(Wheel_Track / (N - Wheel_Width))
        R = atan(Wheel_Track / (N + Wheel_Width))
    }
    
    if(->FL_Wheel & !FL_Wheel:isPlayerHolding()){
        if(!FL_Wheel:isFrozen()){
            FL_Wheel:propFreeze(1)
        }
        FL_Wheel:setAng(Base:toWorld(ang(0, L, 0)))
    }    
    
    if(->FR_Wheel & !FR_Wheel:isPlayerHolding()){
        if(!FR_Wheel:isFrozen()){
            FR_Wheel:propFreeze(1)
        }
        FR_Wheel:setAng(Base:toWorld(ang(0, R, 0)))
    }    
    
    if(->R_Wheel & !R_Wheel:isPlayerHolding()){
        if(!R_Wheel:isFrozen()){
            R_Wheel:propFreeze(1)
        }
        R_Wheel:setAng(Base2:toWorld(ang()))
    }
}

@unknao
Copy link
Contributor Author

unknao commented Dec 23, 2024

A friend of mine experimented with this bug and seems to have found the culprit of the error:

@outputs Curve
let TickAdjust=10
event tick(){
    Curve += TickAdjust    
}

and

let TickAdjust=10
event tick(){
    TickAdjust++
}

seem to produce the same error.

@unknao unknao changed the title E2 failing to account for localized variables from included files E2 does not recognize local variables inside events defined outside of them Dec 23, 2024
@unknao unknao changed the title E2 does not recognize local variables inside events defined outside of them E2 does not recognize local variables inside events defined outside of them when included in another file Dec 23, 2024
@Fasteroid
Copy link
Contributor

Might need to persist it. This looks more like a programmer error waiting to happen than an actual problem with E2 as a language, but the fact it errors in one place and not another is pretty stupid.

@Vurv78
Copy link
Contributor

Vurv78 commented Dec 26, 2024

It's mostly that locals aren't supposed to be accessed from events and it's kind of a hack that they're considered global if you do them at the top level. That assumption gets broken inside includes where the top level variables are no longer globals (pushed to level 1 so they don't interfere with the main script)

@unknao
Copy link
Contributor Author

unknao commented Dec 30, 2024

E2cels stay losing 😔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants