Jump to content

Scratch programming language


Recommended Posts

Hi,

 

I know this might be somewhat controversial, but please hear me out first.

I love automating things. I spent hundreds of hours in games like Factorio and Dyson Sphere Program and I have also tried to automate different things in KSP 1. As an example, automation is great for things that need to be perfectly repeatable (like an ascent with a specific profile) or that are hard to do manually (like suicide burns). The best way to script it in KSP 1 right now is to use kOS but I think there might be a better option. While waiting for KSP 2 I decided to try SimpleRockets 2 (by the way, it's a cool game, go try it out). So I opened the game, downloaded a cool-looking Atlas V and was blown away by what happened next. The rocket knew how to put its upper stage into orbit not just around its home planed but also its moons at a desired altitude! Turns out, SR2 has a built-in visual scripting language called Vizzy you can use to write programs like that. I decided to try it out and just in a few hours I had two programs for performing ascent and landing for me. Here's how the language looks:

Vizzy

SR2 blog post about Vizzy.

This could also be used to complement new tutorials by showing not just a video but an actual rocket flown by a computer to teach new players. And yes, all this can (and has) been done before but I find the experience of using something like kOS far from perfect: you need to install the mod, learn a new scripting language, constantly switch to an external text editor, launch scripts from the command line and debugging is often a pain. If implemented correctly, built-in scripting can improve the player's experience, especially if scripts could be shared through the Steam Workshop for those who don't want to code themselves. And hey, it's not a bad thing either if someone learns how to code a bit while playing KSP 2! And the good thing is, you don't have to reinvent the wheel. This has already been done in SR2 and it works great there.

So what do you think?

Link to comment
Share on other sites

Agree.

Simple visual programming (like Scratch) with functions as software modules and autopiloted key frame automation (it would make it even easier to program than Vizzy). These would be awesome.

We could have the incredible experience of enjoying realistic programmed probes and rovers with comms delay. Launch and watch. Fail, learn, redesign, reprogram and launch another one. Like in real life.

Also check out:

 

Link to comment
Share on other sites

48 minutes ago, Vl3d said:

Agree.

Simple visual programming (like Scratch) with functions as software modules and autopiloted key frame automation (it would make it even easier to program than Vizzy). These would be awesome.

We could have the incredible experience of enjoying realistic programmed probes and rovers with comms delay. Launch and watch. Fail, learn, redesign, reprogram and launch another one. Like in real life.

Also check out:

 

Seen that, that's why I said it's controversial. However, that post focuses more on what, not how. I also don't think we need any additional modules for the automation, just like in SR2 (much less a module for every action). Thing is, your craft would be naturally limited by your progression: you may write a program to fly all the way to Eve but if your craft doesn't have enough delta-v, then well, you can't.

Speaking of key frame automation, we already kind of have that in KSP 1 and it should absolutely be a thing in KSP 2. However, my issue with that is the absence of any inputs, in a sense that your "program" doesn't know anything about the world or the rocket (good luck keyframing suicide burns in stock KSP 1!). But if the devs were to add some inputs, it would be very nice indeed. Still, having a full-fledged language that can do loops, conditions and complex math is much better if you want to tinker with it. And yes, having programmed probes would be sick!

Link to comment
Share on other sites

1 hour ago, MStefan99 said:

my issue with that is the absence of any inputs, in a sense that your "program" doesn't know anything about the world or the rocket

That's why I'm advocating for software modules (these are not physical parts, you add them to the Command and Control Core as items to an inventory).

This way you can select only the functions you desire, they can have tech levels and you can also integrate telemetry, sensors, smart-part conditionals and science into the CCC programming.

And it would all be centralized with upgradable CCC hardware, CCCs could be saved as specialized subassemblies for rocket/plane/rover/boat/submarine, and also you could remotely upgrade the software modules using comms (limited by hardware / CCC inventory space).

Having a distinct CCC means you only need one probe-core per size and you can upgrade it. No more compromises on SAS and other feature if you like a specific size or shape.

Edited by Vl3d
Link to comment
Share on other sites

Personally, I like this idea. And to focus on the “what” of the matter, I feel like a dual visual and text based system (in an already existing language) could offer players who want to get into more complex stuff the option to do so. 
 

Before there is a wave on the “why” of this, I’ll put my opinion that I have stated before: As long as this is optional, not forced, it is fine. There will be lots of people who find automation un-engaging, or contrary to the spirit of the game. And if you forced people to use automation, those claims would have merit. But, making it an optional system to interact with allows everyone to play their own way. 

Link to comment
Share on other sites

set tset to 0.
lock throttle to tset.

set done to False.
set dv0 to nd:deltav.
until done
{
    set max_acc to ship:maxthrust/ship:mass.
    set tset to min(nd:deltav:mag/max_acc, 1).
    if vdot(dv0, nd:deltav) < 0
    {
        print "End burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
        lock throttle to 0.
        break.
    }
    if nd:deltav:mag < 0.1
    {
        print "Finalizing burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
        wait until vdot(dv0, nd:deltav) < 0.5.
        lock throttle to 0.
        print "End burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
        set done to True.
    }
}
unlock steering.
unlock throttle.
wait 1.
remove nd.

SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
Link to comment
Share on other sites

57 minutes ago, Nazalassa said:
set tset to 0.
lock throttle to tset.

set done to False.
set dv0 to nd:deltav.
until done
{
    set max_acc to ship:maxthrust/ship:mass.
    set tset to min(nd:deltav:mag/max_acc, 1).
    if vdot(dv0, nd:deltav) < 0
    {
        print "End burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
        lock throttle to 0.
        break.
    }
    if nd:deltav:mag < 0.1
    {
        print "Finalizing burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
        wait until vdot(dv0, nd:deltav) < 0.5.
        lock throttle to 0.
        print "End burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
        set done to True.
    }
}
unlock steering.
unlock throttle.
wait 1.
remove nd.

SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.

What a terrible programming language!

1 hour ago, siklidkid said:

Kerbal Scratch Program FTW!!!!!!!

Yes! With autopilot software modules and smart-part conditionals!

Then you just say: launch, stage when tank empty, get to 100km orbit, circularize, activate action group 1, whatever.

Edited by Vl3d
Link to comment
Share on other sites

3 hours ago, Vl3d said:

That's why I'm advocating for software modules (these are not physical parts, you add them to the Command and Control Core as items to an inventory).

This way you can select only the functions you desire, they can have tech levels and you can also integrate telemetry, sensors, smart-part conditionals and science into the CCC programming.

But why not give players access to all the data right away? Locking information away behind the tech tree doesn't seem necessary to me when more advanced parts already are. Like, what exactly could "more advanced" information be that needs to be locked? I can see, however, some data being unavailable if you don't have a corresponding part, like having no pressure data if the rocket has no barometer.

Also, why have one centralized computer? Going back once again to SR2, in that game you can have multiple computers, each running its own program at the same time. In my opinion it's actually more convenient to have many smaller scripts rather than combining everything into one and not using half of it. Oh, and each computer in SR2 can also have an interactive display to quickly view or change what's going on. That would also be a nice addition.

Link to comment
Share on other sites

1 hour ago, shdwlrd said:

Yeah, no. I'm not learning code to play a game. I'd rather have an autopilot than scripting. 

Sure, it has to be optional, and with a way to share scripts using something like Steam Workshop you won't have to write them yourself but could use ones created by others.

Link to comment
Share on other sites

2 hours ago, shdwlrd said:

Yeah, no. I'm not learning code to play a game. I'd rather have an autopilot than scripting. 

Autopilot would still theoretically be in the game. It’s just that you would be able to edit it and make it more complex. For example you could program a missile with Orion Drive magazines to nuke your fellow colonies.

Link to comment
Share on other sites

22 minutes ago, BowlerHatGuy2 said:

Autopilot would still theoretically be in the game. It’s just that you would be able to edit it and make it more complex. For example you could program a missile with Orion Drive magazines to nuke your fellow colonies.

Probably best not to bring up violent applications of these things, though we know there are many. There is a very thin line between passively and actively allowing for violence. 
 

1 hour ago, MStefan99 said:

But why not give players access to all the data right away? Locking information away behind the tech tree doesn't seem necessary to me when more advanced parts already are. Like, what exactly could "more advanced" information be that needs to be locked? I can see, however, some data being unavailable if you don't have a corresponding part, like having no pressure data if the rocket has no barometer.

One way this could work is drive space and operations per second. In the game Human Resource Machine (and probably its sequel) you have challenges to fit your code into a certain number of lines or have it perform is a low enough number of steps, which for me is fun. This way, you aren’t artificially limited in what you can code but there is a real progression in what you can do with the computers on your craft. 
 

And remember for people who don’t like coding or autopilot: you don’t have to interact with these systems to play the game. If you don’t like coding, you can just import someone else’s code easily and if you don’t like autopilot, then don’t download autopilot. There are lots of other applications for this code, and if you feel pressured to use autopilot because others are not as comfortable with manual flight, remember that you can set rules on servers to curb automatic flight. I know I won’t be using autopilot and I’ll be playing on a mix of servers with and without it, because sometimes I want to see lots of crashes. 

Link to comment
Share on other sites

In my mind autopilot would be a late game tech, like the target SAS and the Maneuver (Transfer) Tool are in KSP1. Frankly with the automated logistics routing in the new game autopilot is not even necessary for gameplay. It's just cool to have for probe programming and... SWARMS.

It's useful for routing though if the origin - destination system is always dynamic and the periodicity is not synchronous. Think of a space station with high inclination and high eccentricity.

Edited by Vl3d
Link to comment
Share on other sites

10 minutes ago, t_v said:

One way this could work is drive space and operations per second.

Imagine when your expensive rocket with Kerbals crashes because you ran out of drive space... Ugh!

I'd rather have autopilot be later in the tech tree but without these "performance limitations". And for progression there might be additional sensors you could unlock later on to give you more data.

Link to comment
Share on other sites

23 minutes ago, Vl3d said:

Frankly with the automated logistics routing in the new game autopilot is not even necessary for gameplay.

KSP 2 is having automated logistics? What did I miss?

Well, many things in the sequel are strictly speaking "unnecessary" but wouldn't it be cool to have automation anyway? I think the demand for it will be there - kOS was downloaded almost 200k times (KSP 1 sold around 6 million copies) and even SR2 - a much smaller game than KSP - has this feature built-in.

Link to comment
Share on other sites

26 minutes ago, MStefan99 said:

Imagine when your expensive rocket with Kerbals crashes because you ran out of drive space... Ugh!

I'd rather have autopilot be later in the tech tree but without these "performance limitations". And for progression there might be additional sensors you could unlock later on to give you more data.

I agree entirely- I think this may be a miscommunication. Drive space is storage space- not RAM or other short term storage. Once you have a program on the drive, it won’t take up more memory as you go along. It is basically like storage space on a computer or phone (although we probably all know that programs can definitely take up more space when we start installing mods and stuff). So, think of it this way: a capable autopilot is going to be complex and will take up a lot of space, making it an end-game technology simply because no single computer can store the autopilot. Once you have the autopilot installed, it should never run out of space. If you don’t have enough space for the autopilot and only enough for simpler functions, that is similar to not having the tech for an autopilot yet. 

Link to comment
Share on other sites

12 minutes ago, MStefan99 said:

KSP 2 is having automated logistics? What did I miss?

Nate: https://screenrant.com/nate-simpson-interview-kerbal-space-program-2/

"There is a much wider variety of resources that you can harvest. We even have a system that lives alongside the colony system that's called delivery routes, and what it allows you to do is automate resource collection and resource transfer missions that start and end at a colony. So, if I want to just go dig up some stuff somewhere with a specialized drilling vehicle, and then bring it back to a colony? Once I return to the colony, I can make that a delivery route. And then I will continue to receive that amount of that resource in perpetuity, and I can move forward to go find other stuff. Similarly, when I'm transferring resources from one colony to another, I can automate those kinds of missions as well."

"...if you go dig up some rock somewhere and bring them back to a colony, you can automate that mission. If you've gone to a new place that has a new kind of rock on it, then feel free to bring it back and automate that mission."

Link to comment
Share on other sites

3 hours ago, MStefan99 said:

Sure, it has to be optional, and with a way to share scripts using something like Steam Workshop you won't have to write them yourself but could use ones created by others.

Optional or not, it's something I will never use. Even if someone does the work, the extra layer of translation will add a performance hit. 

2 hours ago, BowlerHatGuy2 said:

Autopilot would still theoretically be in the game. It’s just that you would be able to edit it and make it more complex

Won't happen. There's a reason I decided to stop learning coding and not pursue it as a profession or hobby.

Edited by shdwlrd
Link to comment
Share on other sites

4 minutes ago, shdwlrd said:

Even if someone does the work, the extra layer of translation will add a performance hit. 

Why would this affect performance?

4 minutes ago, shdwlrd said:

Won't happen. There's a reason I decided to stop learning coding and not pursue it as a profession or hobby.

+1

There's enough programming to be done with modding

Link to comment
Share on other sites

10 minutes ago, Bej Kerman said:

Why would this affect performance?

It takes a tic to translate the command from one language to another and then another tic to execute the command.

An good example is when a Windows game is running through a translation layer for either Mac or Linux. Even if the game runs well on the Mac or Linux systems, the Windows machine will have better performance because the game is in its native environment and no translation is necessary.

Link to comment
Share on other sites

1 minute ago, shdwlrd said:

It takes a tic to translate the command from one language to another and then another tic to execute the command.

Pretty sure performance hit will be negligible compared to physics and graphics calculations. Besides, if there's no code added then there's nothing to translate.

Link to comment
Share on other sites

×
×
  • Create New...