Author Topic: The Script typo fix  (Read 1658 times)

Offline King Class Scout

  • Posts: 1775
  • Cookies: 893
  • the other half of SFRD
The Script typo fix
« on: January 10, 2019, 06:01:00 PM »
Some of you might have heard by now that I have discovered a Python scripter that has figured out our main glitch problem with scripting.

if you haven't: a random Discord convo had me check into someone with python scripting experience.  I had him check one of the scripts for BC addons that tended to corrupt a lot.  it turns out that many of our crashes are due to spaces being substituted for tabs.  this simple typo is causing the bulk of our problems; Galaxy charts alone has 10 scripts with this typo!

currently, a solution is being worked on.
OS novel fan

Coming Soon: King's Mod Tuning Shop

best line I've ever read
Me: mine [my bridges] would probably be simple to get the characters to use.  the only person that sits is the captian.
Baz: space is vast there[sic] legs will be tired by the time they get to the next planet

Offline Morgan

  • Moderator
  • Posts: 1340
  • Cookies: 65535
Re: The Script typo fix
« Reply #1 on: January 10, 2019, 09:49:28 PM »
it turns out that many of our crashes are due to spaces being substituted for tabs.
:shocked:

You've gotta be kidding me.

Spaces instead of tabs can cause so much trouble?  I'm having a hard time wrapping my head around it.

Offline King Class Scout

  • Posts: 1775
  • Cookies: 893
  • the other half of SFRD
Re: The Script typo fix
« Reply #2 on: January 11, 2019, 05:48:14 AM »
apparently, it's a common python thing that goes way back.

the nutshell is this: if you look at python scrips, you see indented lines.  these indentations need to be made with the tab button on keyboards.  people are substituting regular spaces to create these instead of tabs.  this makes Python go "?!"

I think over the years, people have been writing compensation scripts to work around this.  if Mario's hanging about, he'd know what I meant, as would MLeo.
OS novel fan

Coming Soon: King's Mod Tuning Shop

best line I've ever read
Me: mine [my bridges] would probably be simple to get the characters to use.  the only person that sits is the captian.
Baz: space is vast there[sic] legs will be tired by the time they get to the next planet

Offline FekLeyr Targ

  • DS9FX Team
  • Posts: 490
  • Cookies: 537
Re: The Script typo fix
« Reply #3 on: January 11, 2019, 09:09:32 AM »
Oh my goodness. I had no idea that spaces could cause so much trouble in Python.
At least we can now hope that we'll be able to play BC a bit longer before it crashes once the spaces are replaced by tabs.
TaH pagh, Tah be.

Offline vonfrank

  • Posts: 447
  • Cookies: 182
Re: The Script typo fix
« Reply #4 on: January 11, 2019, 10:57:55 PM »
This is fascinating, and potentially exciting!

Checking a few random files in my install, I see that the "Engineering Extension" mod (which I believe is from QBAutostart) has a ton of spaces instead of tabs. And this is a very common mod for almost everyone.

I wonder if this same issue could be contributing to the stock game's instability as well? If there are spaces in stock scripts instead of tabs it might cause trouble also?

Offline King Class Scout

  • Posts: 1775
  • Cookies: 893
  • the other half of SFRD
Re: The Script typo fix
« Reply #5 on: January 12, 2019, 05:21:45 AM »
the stock instability is in the game engine itself, not the scripts it uses.

Krrks has claimed, however, the spaces for tabs substitute is normal and only applies to the newest versions of Python; those only months old.

I have tested two solutions for this typo, so far.  neither has been able to do a thing, however.  my only instructions were to drag and drop the offending folder onto the python file. no action happens, except the folder is copied into the same area the script is in.  this may be due to the fact that I have the files set to open with notepad for easy quick fix access.  the second solution, an executable, was immediately red-flagged by my computer.

further testing and explicit instructions are required.  I'll keep you posted.

addendum: I have confirmed this typo myself with a Python interpreter.  I had randomly checked a warp warmup script, and it had noted the spaces for tab substitute.  this is what caused me to discuss the situation.
OS novel fan

Coming Soon: King's Mod Tuning Shop

best line I've ever read
Me: mine [my bridges] would probably be simple to get the characters to use.  the only person that sits is the captian.
Baz: space is vast there[sic] legs will be tired by the time they get to the next planet

Offline Lurok91

  • Posts: 1309
  • Cookies: 2062
  • SPMod Developer (Retired)
    • Lurok91 Mods
Re: The Script typo fix
« Reply #6 on: January 12, 2019, 12:10:31 PM »
Consulting with Mario on Maelstrom Mod, I sort of knew Python errors/debugging were an issue Though still to be convinced a major issue on performance/memory.

Offline KrrKs

  • Posts: 461
  • Cookies: 25
Re: The Script typo fix
« Reply #7 on: January 12, 2019, 01:38:02 PM »
[...]
Krrks has claimed, however, the spaces for tabs substitute is normal and only applies to the newest versions of Python; those only months old.
[...]

That looks like my statement on the discord was worded incorrectly and or confusingly. Sorry for that.
What I wanted to say is:

Python versions lower than 3.0 do not use (curly) brackets, like most other programming languages do, to separate logic levels. Instead indentation -and only indentation- is used to specify whether statements and method calls belong inside e.g., a loop (or an if-else block or similar) or outside of it.

Whether the indentation differences used to signal different levels are created using tabs or spaces does not matter, as long as the use is consistent across a method (or file  -can't remenber :idk:). I.e., One XOR the other, never a mix of both styles.

So substituting spaces for tabs, or vice versa, does not make a difference on the runtime behaviour of the code -as long as the indentation differences remain the same.

The actual difference between the two styles seems to be that whitespaces are displayed the same no matter what program is used to view/edit the source code. Tabs on the other hand vary with system, program and settings.

Offline King Class Scout

  • Posts: 1775
  • Cookies: 893
  • the other half of SFRD
Re: The Script typo fix
« Reply #8 on: January 12, 2019, 03:19:53 PM »
what krrks is saying in a nutshell: it don't make no difference.

well, I wanna see if it does!  maybe it'll reduce the hiccups, at least.  and unlike a LOT of people, I saved everything I've ever downloaded, so if something goes wrong...
OS novel fan

Coming Soon: King's Mod Tuning Shop

best line I've ever read
Me: mine [my bridges] would probably be simple to get the characters to use.  the only person that sits is the captian.
Baz: space is vast there[sic] legs will be tired by the time they get to the next planet

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2186
  • Cookies: 1706
  • Life is life
Re: The Script typo fix
« Reply #9 on: January 16, 2019, 12:02:58 PM »
It's not that big of a deal. If the python interpreter parses successfully a script it will work if it doesn't it will reject it. Once a script is parsed it is compiled into byte code (non human readable code) -- Info for BC.

It is generally recommended to either use spaces or tabs and not use both of them (one could successfully utilize both prior to Python 3 -- don't know that status in Python 3 to be honest). 4 Spaces are preferred in most IDEs.
Acta, non verba.
aka USS Sovereign

Offline King Class Scout

  • Posts: 1775
  • Cookies: 893
  • the other half of SFRD
Re: The Script typo fix
« Reply #10 on: January 17, 2019, 06:12:13 AM »
(partial)
It is generally recommended to either use spaces or tabs and not use both of them (one could successfully utilize both prior to Python 3 -- don't know that status in Python 3, to be honest). 4 Spaces are preferred in most IDEs.

hmm...that's part of it, there, then.  the reviewed sample script I sent the pythoner to check had both spaces and tabs, and I seem to remember running into five spaces used as a tab substitute.
OS novel fan

Coming Soon: King's Mod Tuning Shop

best line I've ever read
Me: mine [my bridges] would probably be simple to get the characters to use.  the only person that sits is the captian.
Baz: space is vast there[sic] legs will be tired by the time they get to the next planet

Offline Tethys

  • -=USF=- Co-Leader
  • Posts: 256
  • Cookies: 89
Re: The Script typo fix
« Reply #11 on: June 05, 2019, 09:32:30 PM »
Well this is news, and could account for many of my scripting issues. A lot of scripts I have used have both spaces and tabs in them. Boy, this is gonna be some work. Pushing back any release by months...  :facepalm:

Offline King Class Scout

  • Posts: 1775
  • Cookies: 893
  • the other half of SFRD
Re: The Script typo fix
« Reply #12 on: June 06, 2019, 06:11:56 AM »
unfortunately, it may all have to be done by hand.  the originator of the correction idea had sent me two copies of a tab fixer.  neither a straight up python script nor an EXE created for me to try it worked at all..  python won't read it right as a script, either "loose" or in-game (it causes a BSOD, and may be too new for the version of python BC uses), and the exe was booted off my system for "not being win32/x64 based".

it's too bad, because I'd sent the guy a copy of Galaxy chart's scripts, and it turned out all but 5 scripts have this :P
OS novel fan

Coming Soon: King's Mod Tuning Shop

best line I've ever read
Me: mine [my bridges] would probably be simple to get the characters to use.  the only person that sits is the captian.
Baz: space is vast there[sic] legs will be tired by the time they get to the next planet

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2186
  • Cookies: 1706
  • Life is life
Re: The Script typo fix
« Reply #13 on: June 06, 2019, 03:50:21 PM »
Repeating: If the scripts work there is no need to fix anything. You have tools at your disposal to know if a BC script doesn't work by getting a BSOD or an exception in the logs.

Otherwise if you are editing py files in the future I recommend PyCharm (there is a free edition). It's a python IDE, open a py file with it and if there are mixed tabs and spaces it will detect them and will prompt to fix it for you.
Acta, non verba.
aka USS Sovereign

Offline King Class Scout

  • Posts: 1775
  • Cookies: 893
  • the other half of SFRD
Re: The Script typo fix
« Reply #14 on: June 07, 2019, 05:30:20 AM »
Thanks!  I only have one clash going on, and it seems to be with Galaxy Charts almost exclusively; I only got the version included with the KM's to work right ONCE.  I even managed to get GC to work with the STOCK game, once, with foundation.

please remember, though, I have to look all this stuff back up again when it occurs due to being five years away from the program and forgetting all the little tricks (thank goodness for archived fixes that are still here).  heck, I have to make notes on the bigger video games, even now, till I get stuff memorized.
OS novel fan

Coming Soon: King's Mod Tuning Shop

best line I've ever read
Me: mine [my bridges] would probably be simple to get the characters to use.  the only person that sits is the captian.
Baz: space is vast there[sic] legs will be tired by the time they get to the next planet

Offline Tethys

  • -=USF=- Co-Leader
  • Posts: 256
  • Cookies: 89
Re: The Script typo fix
« Reply #15 on: June 07, 2019, 08:47:36 AM »
Thanks!  I only have one clash going on, and it seems to be with Galaxy Charts almost exclusively; I only got the version included with the KM's to work right ONCE.  I even managed to get GC to work with the STOCK game, once, with foundation.

please remember, though, I have to look all this stuff back up again when it occurs due to being five years away from the program and forgetting all the little tricks (thank goodness for archived fixes that are still here).  heck, I have to make notes on the bigger video games, even now, till I get stuff memorized.

Apologies for being off topic.. I have stuff working in multiplayer from GC. System map. Some other stuff. I got the galactic map to work once, but none of the locations were warpable and it was kind of buggy.

Offline Mark McWire

  • Posts: 83
  • Cookies: 1010
Re: The Script typo fix
« Reply #16 on: June 18, 2019, 11:34:39 AM »
Python uses indents (tabs) to recognize new sections of the command, not brackets or semicolons. That's why Python is popular with schools and universities for learning programming. This sensitizes the students to a clean source code. And unlike Java and C ++ you do not need complete the commands with ";". Python automatically detects loops and IF blocks based on the indents.

BTW: Incidentally, after 2 years of programming my mod I came to the conclusion that the Foundation is "Mist". It causes a lot of stability problems and the constant overriding of methods makes debugging a lot more complicated. I'll do my mods in future only without the involvement of the Foundation.

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2186
  • Cookies: 1706
  • Life is life
Re: The Script typo fix
« Reply #17 on: June 19, 2019, 01:44:10 PM »
I thought for long whether or not should I say something or not, however I simply cannot remain quiet. I do find it obnoxious of you to have Foundation called as "crap". You know you're kind of 16-17 years a bit too late with your statement? On top of that the statement is rather inaccurate.

Is Foundation perfect? No.

Could it have been done better? Probably not. The goal was to get rid of static references to allow modability. And as you may or may not know it was used as a platform for many successful mods ;)
On top of that it was a solution for a problem that many games nowadays also have (when 2 mods modify the same files). It also provided an easy way to inject your code into the base game without having to reinvent the wheel every time you created a new mod.

I would not have any problems if you had articulated your points but simply you chose to call it "crap". I recommend that if in the future you're going to make such bold statements you better have arguments ready. I already have an idea of why you find it difficult to use for your mod, but that doesn't mean that Foundation itself deserves to be called "crap".

Nobody's work deserves to be called crap in fact. You can critique it, say it doesn't suit your needs but calling something crap is where I draw the line. I am by no means an angel myself but I do hold myself on to certain standards.
Acta, non verba.
aka USS Sovereign

Offline Mark McWire

  • Posts: 83
  • Cookies: 1010
Re: The Script typo fix
« Reply #18 on: June 19, 2019, 03:01:47 PM »
The word crap was an automatically translation from google. My English ist not so well, so I use translating tools, if I can't find the right word or grammar.

Maybe its a false translation of "mist" and no I do not mean clouds ;-) I use the German word "Mist" in this case not for crap or shit but for too complicate, too unpredictable.

Personal I do not like programming on basis of overrides. I personally do not use this style for me. There are to many side effect.

In Maelstrom, the mission scripts are build on basis of the original code. So if you override them, you have to change all the mission scripts, too. And not only the one you want to change but all scripts who uses the basic methods of the original source code. That's just unnecessary work.

Of course you can now ask: why? Just use the original source code and switch off all mods for "Maelstrom". And that is exactly the problem I have. I do not want to use the original source code for the missions, but use new menu elements and new spaceships and new technologies. And now explain to me how it should fit together?

The simplest answer is: I change the original Python files, which are called by the mission scripts.

I install my new menus, buttons, handlers and technologies there. I just skip the foundation and make my mods static. 16 or 17 years ago, when the game was brand new, I did not have the knowledge and skills of today. I learned programming only 10 years ago and only now understand the connections of the Python elements. I'm starting right now where Dasher42 was back then. Since there is no real successor to this game, I just skip now 16 years of development and evolution.


Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2186
  • Cookies: 1706
  • Life is life
Re: The Script typo fix
« Reply #19 on: June 19, 2019, 09:14:35 PM »
Quote
The word crap was an automatically translation from google. My English ist not so well, so I use translating tools, if I can't find the right word or grammar.

Maybe its a false translation of "mist" and no I do not mean clouds ;-) I use the German word "Mist" in this case not for crap or shit but for too complicate, too unpredictable.

Then what can I say? Be more careful in the future. This is an English speaking forum. English is also not my primary language but for something to be translated as "crap"... it had to had been in a similar context in your language originally I think.

Quote
Personal I do not like programming on basis of overrides. I personally do not use this style for me. There are to many side effect.

If I generalize your statement then I can say that you're already failing at the basic concept of OOP ;)

Quote
In Maelstrom, the mission scripts are build on basis of the original code. So if you override them, you have to change all the mission scripts, too. And not only the one you want to change but all scripts who uses the basic methods of the original source code. That's just unnecessary work.

Of course you can now ask: why? Just use the original source code and switch off all mods for "Maelstrom". And that is exactly the problem I have. I do not want to use the original source code for the missions, but use new menu elements and new spaceships and new technologies. And now explain to me how it should fit together?

I would offer a suggestion, if I could understand your point. Sorry, but I do not. Care to give an example? Could be easier for you perhaps?

Quote
I install my new menus, buttons, handlers and technologies there. I just skip the foundation and make my mods static. 16 or 17 years ago, when the game was brand new, I did not have the knowledge and skills of today. I learned programming only 10 years ago and only now understand the connections of the Python elements. I'm starting right now where Dasher42 was back then. Since there is no real successor to this game, I just skip now 16 years of development and evolution.

Um, if you learn a programming language (any language), it should not really take you long to master a different one. That I can speak from experience, most languages abide by the same rules after all.
Acta, non verba.
aka USS Sovereign