Wednesday, March 04, 2009

Difficulty Values

I guess I didnt expand on the difficulty values...

What happens is, when a script has its OnLoad event triggered it puts into memory where locked doors are.

The problem lies in two separate lua states needing the data, the easy solution is a simple data structure in C that both can talk to without needing to shoehorn data in and out of separate states

The below code takes a set of co-ordinates and optionally a difficulty value. It tests if the part has recorded unlocking a door at said co-ords, and if not, puts a locked door tile there, otherwise the tile that is passed in is stored. This way when the pick lock function or open door function is called from the master script (global functions like use of skills are separate from the map), they can interact without passing data between in a messy way.

(note RSS readers wont nesecarily show the correct colours below<)

816:
817:function PutDoor(s, r, c, t, diff)
818:    if IsDoorLocked(r, c) == -1 then
819:
820:        diff = diff or Difficulty_Competent
821:        SetTile(s, r, c, TILE_DOOR_LOCKED);
822:        SetDifficulty(r, c, diff);
823:    else
824:        SetTile(s, r, c, t)
825:    end
826:end
827:
828:function OnLoad()
829:    PutChest(s, 31, 58, TILE_BRICKFLOOR, Difficulty_Competent);
830:    PutChest(s, 31, 59, TILE_BRICKFLOOR, Difficulty_Competent);
831:    PutChest(s, 31, 60, TILE_BRICKFLOOR, Difficulty_Competent);
832:    PutChest(s, 31, 61, TILE_BRICKFLOOR, Difficulty_Competent);
833:    PutChest(s, 31, 62, TILE_BRICKFLOOR, Difficulty_Competent);
834:end
835:
836:

The SetDifficulty routine will apply to any tile, since you cant stack locked chests on top of locked doors etc this is not a problem to share the data structure.

It would be much simpler if the global script could call into the map script and for things like strings or integers that is easy, but when it comes to passing anything else between two lua states it becomes a nightmare or nearly impossible with more complex data types that live in different universes (separate Lua states).

Posted by Stu on 03/04/2009 at 04:01 PM Permalink to this post.
Filed Under : ComputersDevelopmentFishguts
Tags:

(0) Comments
Share/Bookmark
Page 1 of 1 pages