untoldwind / KontrolSystem2

Autopilot scripting system for KSP2
Other
54 stars 15 forks source link

color function is not sync when import ? #136

Closed lefouvert closed 5 months ago

lefouvert commented 8 months ago

version 0.5.4.1 (Ckan) assumed tag : Bug

Hi !

I have a weird bug I usually have when I accidently trick the compiler to compile Asynch code into sync function. However, I think it's not the case here.

Here the code : _gitreport::color0.to2

// ko v0.5.4.1
// ok v
// issue#

use { Vessel } from ksp::vessel
use { ULTRAMARINE } from _gitreport::color1 // ko

pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = {
    ksp::debug::DEBUG.add_vector(
        fn() -> vessel.command_modules[0].global_position,
        fn() -> vessel.global_facing.vector.normalized * 50,
        ULTRAMARINE,
        "facing",
        1)
    ksp::game::sleep(120)
}

_gitreport::color1.to2

use { RgbaColor, color } from ksp::console

const ULTRAMARINE: RgbaColor = color(0.0, 0.0, 0.5, 1.0) // ko

Everything compile as expected, however, when I execute the code, I get this in the console, and obviously, nothing happen :

>>>>> ERROR <<<<<<<<<

Module _gitreport::color0 terminated with: Field `_GITREPORTCOLOR1:const_ULTRAMARINE' is inaccessible from method `_GITREPORTCOLOR0/AsyncFunction_main_flight:PollValue ()'

(And I just note than quote mark at the start and the end of error message fields are not the same)

BUT ! when I run this code :

use { Vessel } from ksp::vessel

const ULTRAMARINE: ksp::console::RgbaColor = ksp::console::color(0.0, 0.0, 0.5, 1.0) // ok

pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = {
    ksp::debug::DEBUG.add_vector(
        fn() -> vessel.command_modules[0].global_position,
        fn() -> vessel.global_facing.vector.normalized * 50,
        ULTRAMARINE,
        "facing",
        1)
    ksp::game::sleep(120)
}

Everything goes fine. Weird, isn't it ?

Edit: typo, typo, and typo again...

untoldwind commented 8 months ago

The error message is slightly misleading: If you make it a pub const instead of a const it should work, i.e.

use { RgbaColor, color } from ksp::console

pub const ULTRAMARINE: RgbaColor = color(0.0, 0.0, 0.5, 1.0)

The error is that you should not have been allowed to import a non-pub constant in the first place. I will fix that with a proper error message

lefouvert commented 8 months ago

T_T

What a shame. Obviously. Thank you ^^.

untoldwind commented 8 months ago

In 0.5.5.5 it should no longer be possible to import non-pub constants.

github-actions[bot] commented 6 months ago

This issue is stale because it has been open for 60 days with no activity.

github-actions[bot] commented 5 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.