Return Function (╯°□°)╯︵ ┻━┻

hopy

Active Member
Reaction score
64
Hey everyone, me again. I'm currently working on a day/night system for my map, as well as a little clock window to show players the current time.

After about half a day of messing around I think I've got everything to work, except for one error message. The error message in question is a return action in a function. It's supposed to return the current time of day as a string:
Trigger:
  • TimeOfDayToString
    • Options: Function
    • Return Type: String
    • Parameters
      • Time of Day = 00:00:00 <Time Of Day>
    • Grammar Text: Convert Time Of Day to string
    • Hint Text: Converts a time of day value to a string.
    • Custom Script Code
    • Local Variables
    • Actions
      • General - Return lp_timeOfDay

The error message I get is on the "General - Return lp_timeOfDay" part, and I have no clue why. Also couldn't find anything about this on the interwebs. The message happens when the editor is trying to compile the map (saving/testing), and gives me the following message:
"Script failed to compile: Error parsing return, possibly missing semicolon at the end of the return: ';' (See Trigger Editor for more details)"
Now, by this message I assumed the solution would be "add a ';' " and tada, it's fixed. However this turned out not to be the case, so I was hoping you guys knew what to do.

Odds are that it's something really simple and stupid again, and that I'll look like an idiot again, but this little error is preventing me from testing the entire thing. Thanks for any help in advance, and hope to get a reply soon. :)
 

Dave312

Censored for your safe viewing
Reaction score
269
When you are trying to return a string, you can't just type in the name of your variable and hope it will be converted for you. It won't work which is why you're getting the error.

After having a look around, there doesn't seem to be any built in functions to convert a Time of Day type to a string (or even an integer/real). However I did notice there is a built in function called GetTimeOfDay() which will return a string but it will only return the current time of day (not convert if from a parameter). This function is hidden too so you will have to type it in as custom script. I'm unsure as to whether this will work for you though as it will depend on how you have set up your system (does it use the built in time of day stuff or are you emulating it?)
 

hopy

Active Member
Reaction score
64
When you are trying to return a string, you can't just type in the name of your variable and hope it will be converted for you. It won't work which is why you're getting the error.
I actually had no idea how to do this in SC2, so I got myself a tutorial to help out on this. The actual system is pretty simple:
Is supposed to return me the time of day as a string:
Trigger:
  • TimeOfDayToString
    • Options: Function
    • Return Type: String
    • Parameters
    • Time of Day = 00:00:00 <Time Of Day>
    • Grammar Text: Convert Time Of Day to string
    • Hint Text: Converts a time of day value to a string.
    • Custom Script Code
    • Local Variables
    • Actions
    • General - Return getTimeOfDaySeconds(lp_timeofday)

Creates the dialog label and all (calls upon the function):
Trigger:
  • ------- The time of day clock. >CLOCK<
    • Dialog - Create a Modal dialog of size (270, 150) at (0, 0) relative to Top Left of screen
    • Dialog - Show (Last created dialog) for (All players)
    • Dialog - Create a label for dialog (Last created dialog) with the dimensions (200, 50) anchored to Center with an offset of (50, 50) with the text ("Time of day: " + (Text((Convert Time Of Day to string)))) color set to White text writeout set to False with a writeout duration of 2.0
    • Dialog - Show (Last created dialog item) for (All players)
    • Variable - Set ClockDisplay = (Last created dialog item)

Updates the dialog window label (calls upon the function):
Trigger:
  • Clock update
    • Events
    • Timer - Every 1.0 seconds of Game Time
    • Local Variables
    • Conditions
    • Actions
    • Dialog - Set ClockDisplay text to (Text((Convert Time Of Day to string))) for (All players)

Error I'm getting:
Code:
Script failed to compile: Error parsing return, possibly missing semicolon at the end of the return: ';' (See Trigger Editor for more details)
string gf_TimeOfDayToString (string lp_timeofDay) {
// Implementation
return getTimeOfDaySeconds(lp_timeofday);
}

Alright, what exaclty would you suggest? :D

((EDIT -- little small thing: is it possible to tint/darken the screen for a while via triggers? cant find an option))
 

Dave312

Censored for your safe viewing
Reaction score
269
Replace your current time of day function with this:
Trigger:
  • TimeOfDayAsString
    • Options: Function, Native
    • Return Type: Boolean
    • Parameters
    • Grammar Text: TimeOfDayAsString()
    • Hint Text: (None)
    • Custom Script Code

Once you check the Native option, the Local Variables and Actions section will disappear from the function. Finally you need to select the name of your function (select the first line) and uncheck Based On Name. Then set the Script Identifier to GetTimeOfDay (this must match exactly or else it won't work).

The main thing to be aware of with this function is that you can't add a parameter to it. The function will only ever return the current time of day.


You can use a fade filter to darken a screen by applying a black mask. The trigger action is called Fade In/Out.
 

hopy

Active Member
Reaction score
64
First of all: very sorry for the late reply. I've been quite buisy the past two weeks, and didn't have much time for serious work on my map.

Replace your current time of day function with this:
Trigger:
  • TimeOfDayAsString
    • Options: Function, Native
    • Return Type: Boolean
    • Parameters
    • Grammar Text: TimeOfDayAsString()
    • Hint Text: (None)
    • Custom Script Code

Alright, I followed what you did in your post, I currently have the following:
The main function, to ask up the time of day:
Trigger:
  • TimeOfDayAsString
    • Options: Function, Native
    • Return Type: Boolean
    • Parameters
    • Grammar Text: TimeOfDayAsString()
    • Hint Text: (None)
    • Custom Script Code


The (currently only) part that asks up the function:
Trigger:
  • Dialog - Create a Modal dialog of size (250, 100) at (7, 35) relative to Top Left of screen
    • Dialog - Show (Last created dialog) for (All players)
    • Dialog - Create a label for dialog (Last created dialog) with the dimensions (190, 75) anchored to Center with an offset of (0, 0) with the text (Text((GetTimeOfDay() chat string))) color set to White text writeout set to False with a writeout duration of 0.0
    • Variable - Set ClockDisplay = (Last created dialog item)


The error window I get on saving:
Code:
Script failed to compile: Invalid parameter list (See Trigger Editor for more details)
For this it selects the following part in the Script Compile Errors:
Code:
    libNtve_gf_CreateDialogItemLabel(DialogLastCreated(), 190, 75, c_anchorCenter, 0, 0, StringToText(EventChatMessage(GetTimeOfDay())), Color(100,100,100), false, 0.0);

I don't know exactly what's usefull or not, so I just copied everything. :D
My brain melts when trying to figure this out, and I'm currently tempted to make my own day/night system, based on custom timers and integers. xD

You can use a fade filter to darken a screen by applying a black mask. The trigger action is called Fade In/Out.
Thanks. :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top