Page 1 of 1

FactorioScript - If Statements

Posted: Mon May 16, 2016 4:24 pm
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!

Re: FactorioScript - If Statements

Posted: Mon May 16, 2016 10:59 pm
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?

Re: FactorioScript - If Statements

Posted: Tue May 17, 2016 3:39 am
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.

Re: FactorioScript - If Statements

Posted: Thu May 19, 2016 8:35 am
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!

Re: FactorioScript - If Statements

Posted: Mon Jun 19, 2017 11:56 pm
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…

Re: FactorioScript - If Statements

Posted: Sat Jan 04, 2025 9:04 pm
by BardMorgan
Whatever happened with this? I've read both here and on Reddit about it, but never saw any actual code posted.

Re: FactorioScript - If Statements

Posted: Mon Apr 14, 2025 8:34 pm
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

Re: FactorioScript - If Statements

Posted: Sun Apr 20, 2025 9:52 am
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.