LUADefs

From SimsWiki
Jump to: navigation, search
This article is imported from the old MTS2 wiki. You can help Sims2Wiki by cleaning it up. It's original page with comments can be found at http://old_wiki.modthesims2.com/LUADefs
Definitions Blocks 22508,26328,40384,5652
Starting block

dofile("filename.lua") -- usual dofile includes before parsing

(if statements go here. If they exist, file is terminated with an end since the whole file is inside the if statement. They abide by LUA standard Specs)

(additional functions if any)

Definition Block types and Definition Types

(there are 5 ways of defining variables that I will cover here. Of course other methods exist in LUA, but these ones are used regularily in SC4)

(1)
advisor_anim_types = 
{
  NEUTRAL = 0,
  HAPPY = 1,
  ATTENTION = 2,
  ALARMED = 3
}
make_table_const (advisor_anim_types )

(This table has all things defined within the brackets. This is convenient sometimes due to less typing required. A call would look like "Advisor_anim_types.NEUTRAL")

(2)
hr = advisor_heads : new_record(advisor_ids.TRANSPORTATION, advisor_genders.M) -- create variable HR which is a new advisor head record using the transportation advisor of male gender

hr[advisor_anim_types.NEUTRAL]                = hex2dec("2a42b530")
hr[advisor_anim_types.HAPPY]                  = hex2dec("2a42b532")

-- These two statements define the different animations for moods for the new advisor head HR. the hex2dec value is the instance for a s3d file.

(3)
game.trend_slope = function (trend_type, period_in_months) return 0 end --returns a trand value between from (-100, +100) for the period of time (see game_trends for trend types)
game.trend_value = function (trend_type, num_months_ago) return 0 end --returns a value the trend variable had 'num_months_ago'

-- These definition types create variables with functions as their value. Therefore each time the script is called, the function is executed and the variable is recalculated by using the function.

(4)
advice_types = {}
-- on C++ side this will correspond to advisor ID 
  advice_types.NULL = 0
  advice_types.MYSIM = 1
  advice_types.UTILITIES = 21
  advice_types.HEALTH_EDUCATION  = 22
-- This table has to be extended at the end
make_table_const (advice_types)

-- This type of definition script is almost like the first one. It would seem that they can be used back and forth as required.

(5)

GUIDExemplars = "0xa079ce1b"
GUIDCivicBuildings = "0x07bddf1c"
GUIDResidentialBuildings = "0x67bddf0c"
GUIDCommercialBuildings = "0x47bddf12"

--GUID Definitions such as this may exist outside a bracket like other definition types. It seems they must have an end statement at the end of the file though. Fair enough. 3 letters isnt hard to type. The GUID is the instance for a UI file. :)


Ending Block
end -- only if the if statement was in the starting block

Definitions scripts are softcoded. This means each type of definition used may depend on other types of definitions coded elsewhere in the LUA's. It is neccessary to go right up the file free in dofiles in order to find the originally used tables

Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox