Help Understanding Mod Error Appreciated

So I’ve dedicated a little over 1…possibly 2 weeks to completely overhauling the coding for my mod that was originally made by UME before the code generated from that software became invalidated by updates to GDT. I’ve managed to fix quite a few script errors after getting it to the point where I can upload a private version of the recoded mod, but I just can’t seem to figure out how to fix this particular error:

Error Uncaught error. Please report this to support@greenheartgames.com: Uncaught SyntaxError: Unexpected string (file:///C:/Program%20Files%20(x86)/Steam/steamapps/common/Game%20Dev%20Tycoon/mods_ws/72428655_TEST_Bit_Of_Everything_RECODED/main/code.js:1020) Please restart the game.

This is part of the section the mod is referring to (Which is supposed to be a simple console-related notification) with the letters in bold being the line an error’s being reported on:

(function () {
GDT.addEvent = function (event)
{
id: “1b4c6311-c97c-4a40-aa62-a1b9109363b2”,
date: “8/5/2”,
isRandom: false,
ignoreGameLengthModifier: false,
maxTriggers: 1,
getNotification: function (company) {
return new Notification({
header: “Dox Sales Analysis”.localize(),
text: “The first pair of consoles released under The Dox Line have managed to sell 5,000 units combined in the first month alone, and that number continues to rise as the weeks pass. While this may not be exceptional, it appears to be a solid start for the new company Cryptic Entertainment. It appears that the DoxBox is proving to be the more successful device, as many customers have come to think that the decrease in quality for the DoxSquare in comparison to the DoxBox isn’t worth its portability.”.localize().format(General.getETADescription (‘8/5/2’),
image: GDT.getRelativePath () + ‘/images/notifications/CustomPlatform1V1.png’;
buttonText: “OK”,

        });
    } 
}

}

Now I’ve been trying my best to follow the API for reference, and so far it doesn’t seem to have let me down. I genuinely have no idea if I’m missing a character, might have put something in the wrong way or what, but I’d greatly appreciate some help knowing how to fix this kind of error. I do apologize if I’m coming across as an annoying newb, but in all honesty even though I’m not completely unfamiliar with coding I’m still very inexperienced at it and would just appreciate some help.

it seems to expect another data type. try and int

date: 2,

and look if it works.

Tried your suggestion, and so far all it seems to have done was change the error to “Unexpected Number” on the same line. Going to try and see if entering the original date in double apostrophes does anything…which it doesn’t. It’s odd considering I’ve looked at other codes (for reference only!) and there doesn’t appear to be anything wrong on the surface. Am I probably missing something around that area of code?

edit: the syntax validiator expects ; instead of , everywhere.

i looked at the GDT documentation and it seems what you’ve done is right: it should expect a string in the format you used. i see other issues:

  1. your text: is missing a ) at the end.
  2. your whole function starts with a ( that never gets closed. should be ) at the very end. maybe these fix the issue.

otherwise, have you tried using it like in the example?

(function(){
var myEvent = {
[eventdata]
}
GDT.addEvent(myEvent);
})

This information’s been pretty helpful so far, as I’ve been able to make incremental progress on fixing this portion of my mod. It’s almost completely fixed, but for whatever reason I keep getting error messages about an unexpected token . in the GDT.addEvent(myEvent); section. Isn’t that period necessary?

(Here’s what the code segment looks like now):

(function () {
var myEvent = [
{
id: “1b4c6311-c97c-4a40-aa62-a1b9109363b2”,
date: “8/5/2”,
isRandom: false,
ignoreGameLengthModifier: false,
maxTriggers: 1,
getNotification: function (company) {
return new Notification({
header: “Dox Sales Analysis”.localize(),
text: “The first pair of consoles released under The Dox Line have managed to sell 5,000 units combined in the first month alone, and that number continues to rise as the weeks pass. While this may not be exceptional, it appears to be a solid start for the new company Cryptic Entertainment. It appears that the DoxBox is proving to be the more successful device, as many customers have come to think that the decrease in quality for the DoxSquare in comparison to the DoxBox isn’t worth its portability.”.localize().format(General.getETADescription (“8/5/2”)),
image: GDT.getRelativePath () + ‘/images/notifications/CustomPlatform1V1.png’;
buttonText: “OK”,
}
GDT.addEvent(myEvent);
})
})
}

A few notes:

  • The error reporter really seemed to prefer most fields ending with commas instead of semi-colons.
  • The game seemed to have been really confused when I tried to define the variable for myEvent as {, so that’s why it’s a [.
  • I did make sure that all the brackets and parenthesis were closed a code viewer, turns out UME is still useful for something afterall with that unlocked code writer.

[quote](function () {
var myEvent = [
{
id: “1b4c6311-c97c-4a40-aa62-a1b9109363b2”,
date: "8/5/2",
isRandom: false,
ignoreGameLengthModifier: false,
maxTriggers: 1,
getNotification: function (company) {
return new Notification({
header: “Dox Sales Analysis”.localize(),
text: “The first pair of consoles released under The Dox Line have managed to sell 5,000 units combined in the first month alone, and that number continues to rise as the weeks pass. While this may not be exceptional, it appears to be a solid start for the new company Cryptic Entertainment. It appears that the DoxBox is proving to be the more successful device, as many customers have come to think that the decrease in quality for the DoxSquare in comparison to the DoxBox isn’t worth its portability.”.localize().format(General.getETADescription (“8/5/2”)),
image: GDT.getRelativePath () + ‘/images/notifications/CustomPlatform1V1.png’
;

buttonText: “OK”,
}
GDT.addEvent(myEvent);
})
})
}[/quote]

I’ve bolded the things that you’ve done wrong, atleast from what I can tell from looking. I’ve pasted a version that should be correct here for simplicity and visual reasons. I haven’t tested it, but this should be correct (not 100% if there’s a difference between using a single or double quotation marks in JavaScript too).

1 Like

You guys are awesome, now not only do I have that particular event functioning in my mod’s code, I also know how to format other events/notifications similar to it. Thanks to this I now have…at least a little bit more understanding about formatting mods for this game. Hopefully there are any other problems with this mod’s code I can figure them out myself.

1 Like

Glad to hear that it works :slight_smile: Don’t hesitate to ask any further questions :wink:

2 Likes

So you don’t mind if I ask another question? I don’t mean to bombard anyone with too many questions. There have been plenty of different errors I’ve had to fix in my efforts to recode the mod I’ve been working on, and I’ve been able to fix most of it myself, I just can’t help but admit there are instances where I just can’t see / don’t understand why certain errors are being recorded.

Even though I’ve been making substantial progress with my mod so far, I’m getting another weird error this time by the case of Uncaught SyntaxError: Unexpected identifier on line 1121. I’ll post the section of the code like I did last time, but this time I’ll be courteous enough to abridge the text field and bolden the line of the script that’s causing problems like list time.

(function () {
var icon = GDT.getRelativePath() + ‘/images/platforms/DoxTesseract Final.png’;
GDT.addPlatform(
{
id: ‘DoxTesseract’,
name: ‘DoxTesseract’,
company: ‘Cryptic Entertainment’,
startAmount: 0.5,
unitsSold: 1.0,
licencePrize: 100000,
published: ‘28/1/1’,
platformRetireDate: ‘34/1/1’,
developmentCosts: 100000,
genreWeightings: [0.9, 1, 1, 0.8, 0.9, 0.7],
audienceWeightings: [0.8, 0.9, 1],
techLevel: 6,
iconUri: icon,
events: [
{
id: ‘2a33185f-49dc-486c-a829-33a13dad374c’,
date: ‘25/11/3’,
getNotification: function (company) {
return new Notification({
header: “The Final Product of the Dox Line”.localize(),
text: “…”.localize().format(General.getETADescription(‘25/11/3’, 34/1/1’)),
image: icon
});
}
}
]
});
}

Here’s the oddest thing though, the code for all the consoles before it in my mod is written in the same way and work (or at least, it should be. I’ve been cross-checking them extensively and haven’t found any problems that I can see at least). What I have noticed posting this into the UME code viewer is that unlike all the other platforms, none of the opening brackets are highlighted with the closing brackets when I highlight them.

You’re missing a single quotation mark before the date 34/1/1 on the line above :slight_smile:

1 Like

Just to clarify, he’s talking about this line:

1 Like

-Tests the line fix, discovers it really was a missing quote…facepalms- Seriously, the only reason it was broken was because I forgot one character? Been so long since I’ve seen an error like that, I’m going to need to check similar instances to that and make sure that mistake isn’t repeated. Wow that was kind of dumb, but at least that section isn’t broken anymore. How did I not see that?

To be fair, it took me a while to figure that out too. It’s always the small things that you never see. :smile:

1 Like

Alright at this point I am literally at the very last error of recoding this mod (at least, this version. Sure it’ll break plenty of times once I finish playtesting it and deem it worthy of additional content). The only thing stopping me from being able to playtest with this mod is this error: Uncaught SyntaxError: Unexpected end of input.

Basically, it doesn’t seem to understand when the code actually ends, and I’ve been trying to put marks at the very end, yet every time I do it complains about unexpected tokens. So I guess my final question is how do I actually format the end of the script?

Assuming you have (function () { at the top of your mod, to end this, all you need to put on your last line is })()

1 Like

One would think. This is the final part of my mod followed by nothing else:

(function () {
GDT.addTopics([
{
id: “Cyborg”,
name: “Cyborg”.localize(“game topic”),
genreWeightings: [1, 0.8, 0.7, 0.9, 0.7, 0.6],
audienceWeightings: [0.6, 0.9, 1],
}
]);
})()

Yet here’s the error I’m getting: Uncaught SyntaxError: Unexpected end of input. I think I might be forgetting one last thing, just not sure where. I appreciate the help I’ve received so far, and I’d be even more grateful if I could get this one last error resolved.

I’m going to need more information than this. Does it tell you what line the error occurs on?

From what I can tell from all the things you’ve posted, is that you put every command (GDT.addTopics, etc. Not sure what the right word to use for this is to be fair) within its separate function. If you actually do do this, it’s probably best if you put all commands in one function.

EDIT: This is a complete wild card, but what if you remove the comma at the end of audienceWeightings?

1 Like

Terribly sorry about not specifying the line, thought I did earlier. I did remove the audienceWeightings comma, and it didn’t seem to change anything. The full error on the same script I posted last time is:

Error Uncaught error. Please report this to support@greenheartgames.com: Uncaught SyntaxError: Unexpected end of input (file:///C:/Program%20Files%20(x86)/Steam/steamapps/common/Game%20Dev%20Tycoon/mods_ws/72428655_TEST_Bit_Of_Everything_RECODED/main/code.js:2002) Please restart the game.

There’s just one problem: There is no line 2002, there’s nothing there. It ends on line 2001.

Here’s the code segment again just for reference:

(function () {
GDT.addTopics([
{
id: “Cyborg”,
name: “Cyborg”.localize(“game topic”),
genreWeightings: [1, 0.8, 0.7, 0.9, 0.7, 0.6],
audienceWeightings: [0.6, 0.9, 1]
}
]);
})()

For the past couple days I’ve been experimenting with a variety of ways to try and end the input of my mod, and what I can conclusively state right now is that for whatever reason I keep getting one of two results:

  1. The mod reports an unexpected end of input if })(); or })() are absent.

  2. The mod reports an unexpected token } or ; if })() or })(); are used respectively.

Even though I’m still a damn newb when it comes to scriptwriting, I’m beginning to suspect that there’s an issue with formatting. It’s just confusing me as to what that issue might be.

Sometimes, when i code a little bit. I’m like:

My code doesn’t work, why?
My code DOES work! But why?