FactorioScript - If Statements

Post pictures and videos of your factories.
If possible, please post also the blueprints/maps of your creations!
For art/design etc. you can go to Fan Art.

User avatar
DemiPixel
Long Handed Inserter
Long Handed Inserter
Posts: 72
Joined: Mon Mar 21, 2016 7:27 am
Contact:

FactorioScript - If Statements

Post by DemiPixel »

If you have no idea what FactorioScript is, here is a link to the original post

Here is the if statement showoff: https://gfycat.com/DaringDeliciousAmericanlobster

You can read the reddit post for more details!
Here's the code:

Code: Select all

chain {
  if crude_oil*3 > 5 && water+5 < 10 {
    water += 6
  }
}
And since the forum section description says that it likes blueprint strings...

Code: Select all

H4sIADLrOVcAA82Y4Y7aMAzHXwX145aeSIHeTbfsRU5TFVIDkdqkSlO2ruLdlxYQFEibaHCMTyCnjv3L37FLKieZZDSbJKQBobnmUJKmETQHEuSQ8ioPIQOmFWdhITMIUCFLs0wK0vwm4evLAtUkxC+LHWJSCLPSmIyLjwAHP0mjIDXuOs91wlMSIcYVq7huf+AdOjPN7aZXu+nNbsLTXftBh2yo4nqTgzaJMJkvuaBaqot04kM6bsng1vtHEN2yzfpxtSuNy5QfPJ6CIc2Kq1InJV8LmpFG14UJdpVVPA3QPnKmqhRCybOgc1JqKrTZQBagaBd68CVAstJFdemGa8iPXpa0NKkvqywDHeZ0Tf9wAcE5oRQYT0HZ8Sy88PTOOhpgFQ+zOoR1G5RDhidmC/M1L6hqUyPBD2doVOWGReuoqBMmK6GTlZJ5woV52hwWzcqOpI/U5neT2uKOUvtFNag+sjOZfXUgtgG6rY/EfMQ18wIy/2xx9fI68cHTnqa+P0xTo/wiL36zPj9k09M52rUCEH1ZjlxznqV7RTfqwSVPLVh8t4LF+JKwX8VuudIVzY4p740hULY5Zzd1qdwhV558pv8Nn+EbLXbhcsuFHw9PHNOn8QixyyQxAsRhVDzMVjPXUbE/zH0bmPMi3znPs5T71yO+6rfWc4sdR9rInmpkn3YfdXG4CcLx5hgXRtSpwrlMkLUwcE8GY/1yuF1et7rYfiqX5zygiPlj+yV+TL/UqvJtl37THJ65jnM4/rcScIDopn+rIz9Onq8BV4J/FKfPnzHGCtbv5fOqZyKX6dWtbof6wYXt9UklbmG+BVXrDRdr91ofv8Bjz/+AbkjTbMdZ90zDRQqmQ6OB3U1s+1URGqoz4/Vdga6UmCTvINK/AtXb1ewSAAA=
Maybe with this you can help explain to me why those combinators are teleporting upwards!
piriform
Fast Inserter
Fast Inserter
Posts: 117
Joined: Mon Jan 25, 2016 10:02 pm
Contact:

Re: FactorioScript - If Statements

Post by piriform »

This is very exciting work with tremendous potential. Is your plan to partition it and do a staged release or wait until it's fully baked?
User avatar
DemiPixel
Long Handed Inserter
Long Handed Inserter
Posts: 72
Joined: Mon Mar 21, 2016 7:27 am
Contact:

Re: FactorioScript - If Statements

Post by DemiPixel »

piriform wrote:This is very exciting work with tremendous potential. Is your plan to partition it and do a staged release or wait until it's fully baked?
I can't imagine I'll be able to do the whole thing alone. People on reddit have been begging me to put it on a github so I just want to finish enough that it doesn't seem like a project where I just got lazy.
vanatteveldt
Filter Inserter
Filter Inserter
Posts: 947
Joined: Wed Nov 25, 2015 11:44 am
Contact:

Re: FactorioScript - If Statements

Post by vanatteveldt »

looks great!

@demipixel: just put the code on github. The idea of getting a project into a certain shape before publishing is really old-fashioned :). Having a bunch of unfinished projects on github doesn't look like you're lazy, it looks like you're willing to share!
dgw
Fast Inserter
Fast Inserter
Posts: 197
Joined: Tue Apr 12, 2016 7:06 pm
Contact:

Re: FactorioScript - If Statements

Post by dgw »

Went looking around all over for something to help me get a handle on combinators and set up balancing trains between two loading stations at my iron smelting, and found this (actually, on reddit first). And then I noticed that there's no trace of a released anything for it—no source code, no GitHub repo, nothing. I guess this really did end up being unfinished, but man, was I excited to try scripting the behavior I wanted from a combinator array and getting a blueprint to do just that…
BardMorgan
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sun Dec 08, 2024 3:59 pm
Contact:

Re: FactorioScript - If Statements

Post by BardMorgan »

Whatever happened with this? I've read both here and on Reddit about it, but never saw any actual code posted.
giodueck
Manual Inserter
Manual Inserter
Posts: 4
Joined: Fri Mar 15, 2019 6:12 pm
Contact:

Re: FactorioScript - If Statements

Post by giodueck »

viewtopic.php?t=50722

Another user made their own version and posted the results to github. Not the same and probably outdated for 2.x, but worth a look
Premu
Fast Inserter
Fast Inserter
Posts: 150
Joined: Wed Nov 13, 2019 4:40 pm
Contact:

Re: FactorioScript - If Statements

Post by Premu »

Hm, I checked this link out. The problem I see here is that a scripting language is not a good way to describe combinator circuits.

As I started to use them, I treated signals as variables, and tried to emulate small programs. It lead to very bloated and problematic designs. Look at this nonsensical pseudo-code:

Code: Select all

int func(int a, int b, int c) {
	x = a * b;
	if (c != 0) then {
		x = x / c;
		}
	return x;
}
One assumption when handling that code is that all variables there will not be changed unless the code says so. This is not the case for Factorio combinators. In one tick you can check if a signal is not 0 - but if you want to react on it, you'll have to wait a tick, and in this tick the value could have been changed to 0. So you have to add some signal delay to ensure your condition is actually valid.

Also, in a programming language is really hard to describe things to be done in parallel. And you certainly would not write something like that:

Code: Select all

if (iron-ore > 8000) then L=1;
if (iorn-ore > 16000) then L=1;
if (iron-ore > 24000) then L=1;
and expect L to be 3 if iron-ore is larger than 24000 - except that's exactly how you'd set up the circuitry in Factorio.

So transforming logical code into a reliably and reasonable sized combinator circuit is a very hard problem, and probably suffers from a lot of border line cases in which complicated set-ups will behave strangely.

A better way to actually describe these combinator circuits would probably a variant of VHDL. I'm not an electronic engineer, so I don't really know it. So I would not dare to define such a language. Perhaps someone else with such a background might feel fancy.
Post Reply

Return to “Show your Creations”