Jump to content

Recommended Posts

Hello :-)

 

I am planning to extend the mouseover from "widgets/uiclock", adding the time left in the current season. I succesfully did this to Dont Starve using onFocus and values from SeasonManager().

 

But it seems like DST does not have the class at all. I tried to circumvent this problem and call for season.lua:

NUIClock.UpdateWorldString =  function (self)			self._text:SetString(NUISeasons._season:value())	self._showingcycles = falseend

Obviously, I had no luck. So Im devastatingly searching for a way to get equivalents for .daysleft and .currentSeason. Any Idea?

Edited by Micha

@przemolsz, I was just about to post here, got ninja'd.

 

 

@Micha, you can get the remaining days in a season by listening for the WorldState "remainingdaysinseason".

 

Here is some example code.

 

local function UpdateDaysRemaining(inst)-- TODO: Implement the update code.endlocal fn(inst)inst:WatchWorldState("remainingdaysinseason", UpdateDaysRemaining)return instend 

That solved my problem, thank you :-)

 

 

Please allow me some followup questions:

 

- Searching my filesystem for "theworld" didnt show up anything. How- / Can I dig into the fields and functions of "TheWorld"?

 

- Why didnt my example work? Cant I call stuff from /components/ or did I just do wrong?

 

- I am unexperienced in writing code for games. How do you guys search for data sources in general? I grep'ed the files for relevant Strings, trying to find a context and then just try to call->extend the class or override the function. Am I on the wrong lane here?

Edited by Micha
local NUISeasons = require "components/seasons"local NUIClock = require "widgets/uiclock"

As NUIClock is a valid object, I thought i found a proper way of loading class instances that are singletons. Obviously not. Digging more through the forums, I now have seen this way as well:

local hounded = GLOBAL.TheWorld.components.hounded.instprint(hounded:GetDebugString())print(hounded._timetoattack)

Prints are a valid debug String and a nil. .inst seems to be designed to hold the single instance of hounded to be accesible, and the debug String does work as well. Accessing the local field however does not work (I guess because its local *facepalm*). Overwriting GetDebugString() and telling him to just return me _timetoattack should work, but by paying the price of loosing some internal code. Sorry for ranting^^

 

I guess my general problem is that I dont understand how to load the different types of objects, related to their scopes. The ways seem to differ.

Edited by Micha
local hounded = GLOBAL.TheWorld.components.hounded.inst

In this case, hounded == TheWorld. In a component, inst usually refers back to the entity that the component is attached to. Remove inst from the end there and you should get the output you're looking for.

 

Edit: I would argue that generally when approaching at least DST's Lua code, Objects are not that useful a concept. It's more helpful to just think in terms of tables, because that's all that objects are, once they're constructed.

Edited by rezecib

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...