Can't get game to recognise script
Moderator: OpenTTD Developers
- SquireJames
- Tycoon
- Posts: 1863
- Joined: 07 Aug 2004 11:56
- Skype: squirejames5
- Location: Stoke-on-Trent
- Contact:
Can't get game to recognise script
Hello there,
Trying to run a quick test version of my Historical Events script, but I have a problem; the game doesn't recognise it when it comes to selecting a game script. I've download NoCarGoal and that appears as an option, but not my script. I've tried putting it in a TAR, i've tried editing the info.nut so it's practically identical to NoCarGoals but nothing seems to want to work. I can't even test my script to see if it's going to work at all until I can resolve this issue.
Any ideas? What causes scripts not to be recognised?
Trying to run a quick test version of my Historical Events script, but I have a problem; the game doesn't recognise it when it comes to selecting a game script. I've download NoCarGoal and that appears as an option, but not my script. I've tried putting it in a TAR, i've tried editing the info.nut so it's practically identical to NoCarGoals but nothing seems to want to work. I can't even test my script to see if it's going to work at all until I can resolve this issue.
Any ideas? What causes scripts not to be recognised?
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: Can't get game to recognise script
That's all *pretty vague*
You could start making it easier for us by
- actually giving the exact locations you put stuff
- aproviding us with your actual script...
- checking whether you also have all libraries you need for NoCarGoal
- Verifying that you got a recent nightly of OpenTTD as NoCarGoal won't run with 1.2.x.
- Verifying that you chose your own script identifier instead of keeping NoCarGoal's
You do not need to put things into a tar. For all that OpenTTD cares in this context, a tar acts like a directory.
You could start making it easier for us by
- actually giving the exact locations you put stuff
- aproviding us with your actual script...
- checking whether you also have all libraries you need for NoCarGoal
- Verifying that you got a recent nightly of OpenTTD as NoCarGoal won't run with 1.2.x.
- Verifying that you chose your own script identifier instead of keeping NoCarGoal's
You do not need to put things into a tar. For all that OpenTTD cares in this context, a tar acts like a directory.
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: Can't get game to recognise script
You may also want to consider visiting the #openttd irc channel. Install problems are usually much easier to resolve interactively.
- SquireJames
- Tycoon
- Posts: 1863
- Joined: 07 Aug 2004 11:56
- Skype: squirejames5
- Location: Stoke-on-Trent
- Contact:
Re: Can't get game to recognise script
Right,
I've put my files in the content_download\game folder, in a separate subfolder called HistoricEvents-1.
Actual script is as follows. Probably won't work but all I was trying to do is get the thing to load, then I could work on it. Right now it is simply supposed to produce two welcome messages; one in a blue message box the other as a news item.
Currently running a Daylength patch build, h211d0563. As mentioned, other scripts (NoCarGoal, Split and Tutorial) all work fine.
Not sure about this script identifier thingy. In info.nut right? I'll try changing it and seeing if it helps.
I've put my files in the content_download\game folder, in a separate subfolder called HistoricEvents-1.
Actual script is as follows. Probably won't work but all I was trying to do is get the thing to load, then I could work on it. Right now it is simply supposed to produce two welcome messages; one in a blue message box the other as a news item.
Code: Select all
// This function displays a welcome message to the given company
function MainClass::Welcome(company_id)
{
if(GSController.GetSetting("display_welcome_message") == 1)
{
GSGoal.Question(0,
company_id,
GSText(GSText."Welcome"),
GSNews.Create(GSNews.NT_GENERAL,"Welcome too!"
GSGoal.QT_INFORMATION,
GSGoal.BUTTON_CLOSE);
}
}
Not sure about this script identifier thingy. In info.nut right? I'll try changing it and seeing if it helps.
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: Can't get game to recognise script
Do NOT put anything manually in content_download or any of its sub dirs. It's meant for OpenTTD's content service, no guarantee will be given that things remain untouched there from automatic mechanisms. Use the normal 'game' folder adjacent to 'content_download' for manual stuff (similar arguments goes for newgrfs, ais, ...)SquireJames wrote:Right,
I've put my files in the content_download\game folder, in a separate subfolder called HistoricEvents-1.
OpenTTD will only show one of the scripts, if they claim to be the same. Identifier distinguish different things which are not an update for a previous version of the same thing.Not sure about this script identifier thingy. In info.nut right? I'll try changing it and seeing if it helps.
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
- SquireJames
- Tycoon
- Posts: 1863
- Joined: 07 Aug 2004 11:56
- Skype: squirejames5
- Location: Stoke-on-Trent
- Contact:
Re: Can't get game to recognise script
Alrighty, I moved the folder. Now in the normal folder structure as you described.
My info file looks like this
My info file looks like this
Code: Select all
require("version.nut");
class FMainClass extends GSInfo {
function GetAuthor() { return "SquireJames"; }
function GetName() { return "Historic Events"; }
function GetDescription() { return "Basic script that produces historical news articles for your OpenTTD games"; }
function GetVersion() { return SELF_VERSION; }
function GetDate() { return "2012-08-14"; }
function CreateInstance() { return "MainClass"; }
function GetShortName() { return "HIST_"; }
function GetAPIVersion() { return "1.2"; }
function GetUrl() { return "None"; }
RegisterGS(FMainClass());
Re: Can't get game to recognise script
The short name must be exactly 4 letters long. No more, no less.
Also you have unbalanced parenthesis in your welcome function. This means that the NoGo compiler will fail to compile your code at startup of OpenTTD. That is why you dont see it in the GS list. Start OpenTTD with the debug flag if you are in Windows to get a console window where squirrel compile errors are shown.
Also you have unbalanced parenthesis in your welcome function. This means that the NoGo compiler will fail to compile your code at startup of OpenTTD. That is why you dont see it in the GS list. Start OpenTTD with the debug flag if you are in Windows to get a console window where squirrel compile errors are shown.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Re: Can't get game to recognise script
This is the only reason it won't show up in the list.Zuu wrote:The short name must be exactly 4 letters long. No more, no less.
Game scripts are not compiled before the game starts (except info.nut, for obvious reasons).Also you have unbalanced parenthesis in your welcome function. This means that the NoGo compiler will fail to compile your code at startup of OpenTTD. That is why you dont see it in the GS list. Start OpenTTD with the debug flag if you are in Windows to get a console window where squirrel compile errors are shown.
- SquireJames
- Tycoon
- Posts: 1863
- Joined: 07 Aug 2004 11:56
- Skype: squirejames5
- Location: Stoke-on-Trent
- Contact:
Re: Can't get game to recognise script
Well, I changed the short name. Still doesn't show, so bang goes that. I'll keep comparing my file with NoCarGoals and see if I can work out why it works and mine does not.
Re: Can't get game to recognise script
If the above is an exact copy/paste of your info.nut you're also missing a } at the end of the class.
- SquireJames
- Tycoon
- Posts: 1863
- Joined: 07 Aug 2004 11:56
- Skype: squirejames5
- Location: Stoke-on-Trent
- Contact:
Re: Can't get game to recognise script
Need a tad more help here. Thanks to you gentleman it now loads and runs. However I haven't quite grasped this squirrel code it seems. Probably a schoolboy error to you lot but what am I missing from getting this to work (trying to get a message to appear when the date is Jan 3rd 1950, just as a test)
Code: Select all
/* Import SuperLib for GameScript */
import("util.superlib", "SuperLib", 24);
Result <- SuperLib.Result;
Log <- SuperLib.Log;
Helper <- SuperLib.Helper;
ScoreList <- SuperLib.ScoreList;
Tile <- SuperLib.Tile;
Direction <- SuperLib.Direction;
Town <- SuperLib.Town;
Industry <- SuperLib.Industry;
class MainClass extends GSController
{
_load_data = null;
constructor()
{
}
}
function MainClass::Start()
{
this.Init();
// Wait for the game to start
this.Sleep(1);
// Welcome human player
local HUMAN_COMPANY = 0;
GSNews.Create(GSNews.NT_GENERAL, GSText(GSText.STR_HELLO_WORLD, HUMAN_COMPANY), HUMAN_COMPANY);
while (true) {
local loop_start_tick = GSController.GetTick();
this.HandleEvents();
this.DoTest();
// Loop with a frequency of five days
local ticks_used = GSController.GetTick() - loop_start_tick;
this.Sleep(Helper.Max(1, 5 * 74 - ticks_used));
}
}
function FirstDate::Init()
{
GSDate.GetDate(1950, 01, 03)
GSNews.Create(GSNews.NT_GENERAL, GSText(GSText."Something happened!", HUMAN_COMPANY), HUMAN_COMPANY);
}
function MainClass::Init()
{
if (this._load_data != null)
{
// Copy loaded data from this._load_data to this.*
// or do whatever with the loaded data
}
}
function MainClass::HandleEvents()
{
if(GSEventController.IsEventWaiting())
{
local ev = GSEventController.GetNextEvent();
if(ev == null)
return;
// check event type
// handle event
}
}
function MainClass::Save()
{
Log.Info("Saving data to savegame", Log.LVL_INFO);
return {
some_data = null,
some_other_data = null
};
}
function MainClass::Load(version, tbl)
{
Log.Info("Loading data from savegame made with version " + version + " of the game script", Log.LVL_INFO);
// Store a copy of the table from the save game
// but do not process the loaded data yet. Wait with that to Init
// so that OpenTTD doesn't kick us for taking too long to load.
this._load_data = {}
foreach(key, val in tbl)
{
this._load_data.rawset(key, val);
}
}
function MainClass::DoTest()
{
}
Re: Can't get game to recognise script
So you have FirstDate::Init, but nowhere you define that class.
---
In the main loop you need to keep checking if the date today is equal to or greater than the day in your event. When that condition fullfills, call GSNews.Create and set a flag that this news have been sent so you don't send it again. (this flag you will have to check for in the if-statement that check date and combine these checks with an AND)
Example:
I leave for you to figure out how to generalize this code so that you don't have to repeat so much code for each event.
---
In the main loop you need to keep checking if the date today is equal to or greater than the day in your event. When that condition fullfills, call GSNews.Create and set a flag that this news have been sent so you don't send it again. (this flag you will have to check for in the if-statement that check date and combine these checks with an AND)
Example:
Code: Select all
local fired = false;
local event_date = GSDate.GetDate(1950, 01, 03)
while (true) { // main loop
if(!fired && GSDate.GetCurrentDate() >= event_date)
{
// call GSNews.Create here for your event. Note that your GSNews call is invalid or more specificly, your use of GSText.
// the string STR_HELLO_WORLD used here is defined in lang/english.txt
GSNews.Create(GSNews.NT_GENERAL, GSText(GSText.STR_HELLO_WORLD, HUMAN_COMPANY), HUMAN_COMPANY);
fired = true;
}
GSController.Sleep(32); // sleep a half day
}
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
- SquireJames
- Tycoon
- Posts: 1863
- Joined: 07 Aug 2004 11:56
- Skype: squirejames5
- Location: Stoke-on-Trent
- Contact:
Re: Can't get game to recognise script
Thanks Zuu. Was (sort of) aware of the FirstDate thing, but I couldn't seem to get it to work under the MainClass so I wondered if a separate class was needed. I'll give that code a go and see if I can rationalise it. I am figuring some kind of chained IF statement ("If this date then this, else if this date this, else if etc etc")
- SquireJames
- Tycoon
- Posts: 1863
- Joined: 07 Aug 2004 11:56
- Skype: squirejames5
- Location: Stoke-on-Trent
- Contact:
Re: Can't get game to recognise script
Right, slight issue here. I am afraid the script you kindly gave me doesn't function.
"Your script made an error: the index 'fired' does not exist"
"fired" is declared in the script though. I copied and pasted your code exactly. Currently trying to work out what's wrong.
EDIT: Right, if I declare those variables outside of my function, it does not cause a script crash but it doesn't work either. No newspaper article appears on the date specified.
"Your script made an error: the index 'fired' does not exist"
"fired" is declared in the script though. I copied and pasted your code exactly. Currently trying to work out what's wrong.
EDIT: Right, if I declare those variables outside of my function, it does not cause a script crash but it doesn't work either. No newspaper article appears on the date specified.
Re: Can't get game to recognise script
Please upload the complete code in a zip or tar file. Do not put it in code tags in your post. I wonder if you replaced the old main loop with my code. Additionaly full code in .nut files give automatic colur coding etc.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
- SquireJames
- Tycoon
- Posts: 1863
- Joined: 07 Aug 2004 11:56
- Skype: squirejames5
- Location: Stoke-on-Trent
- Contact:
Re: Can't get game to recognise script
I appreciate the help but clearly this isn't something I am likely to grasp. I gave it a go though I suppose.
Re: Can't get game to recognise script
Its a good idea to know some programming to program Game Scripts. If you want to learn programming without knowing it since before, there are better environments to start with than Squirrel programming in OpenTTD. Try to start with something smaller and with a book or guide that teach programming.
After you've learned to program eg. Python, C++ or any other language, you could come back and try Game Scripts again, and I'm sure you will find it easier.
Edit: A topic that is useful to know when working with game scripts is the object oriented programming model.
After you've learned to program eg. Python, C++ or any other language, you could come back and try Game Scripts again, and I'm sure you will find it easier.
Edit: A topic that is useful to know when working with game scripts is the object oriented programming model.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Junctioneer (a traffic intersection simulator)
Who is online
Users browsing this forum: No registered users and 15 guests