I'm trying to structure my variables and code in a manner that PulpScript doesn't seem to expect. Basic structures and arrays would be AWESOME but may be out of scope.
I'm iterating on plans to work around this by using tiles as data structure containers. For example, i've created a TOOL tile, which holds information about the various tools my player might use in the game (for me that's a camera, sonar, radar, GPR).
I plan to use one frame in the tile to represent each of the various tools i'm creating. This way I can create more tools in the future by adding a frame instead of rewriting a mass of spaghetti code.
For this I figure i'd start my room with one tool tile in it somewhere then call its "init" handler:
on init do
// a bad hack to simulate an array of tools
_tool_cnt = 4 // number of tools i've defined
_tool_0 = "camera" // looks forward, sees objects
_tool_1 = "sonar" // looks around, sees objects
_tool_2 = "radar" // looks in cone, sees walls
_tool_3 = "GPR" // looks under ground, sees hazards
// are the tools VALID (available)?
// default to yes, but maybe one breaks?
_v_tool_0 = 1
_v_tool_1 = 1
_v_tool_2 = 1
_v_tool_3 = 1
// costs in nondescript units
_c_tool_0 = 1 // camera costs 1
_c_tool_1 = 2 // sonar costs 2
_c_tool_2 = 4 // radar costs 4
_c_tool_3 = 8 // gpr costs 8
end
now i have all the data setup. later on if i want to leave a tool in the room for my player, all i need to do is drop a TOOL tile there and set its frame to the proper index for the specific tool in question. all good so far.
when a player picks up the tool i'll read the frame number from that tile and set the appropriate valid flag for that tool. i'll write code in the tile script itself for this.
later on i'll use a menu to let a player select from a list of tools the possess - and i'll need to update some variables in the main loop when that happens. i could use a bunch of if/then logic, but that's brittle and i already have one place where my code must be brittle (the init handler above). I'd like to avoid that.
so i'm trying to do something better. when the player selects an item i plan to take note of the tile they are standing on (or some other dedicate spot), swap a TOOL item tile onto the same coordinates, set the tile frame to the index of their selection from the menu (to turn that generic tool tile into the exact tool selected), call the tile's getParams handler (below) then swap back to the original tile to clean up. Doing all that should let me set some global variables so when the user activates their selected tool I know what it is supposed to do...
on getParams do
t_idx = frame
t_nam="_tool_{t_index}"
t_val="_v_tool_{t_index}"
t_cst="_c_tool_{t_index}"
// TODO: figure out how to read from variables named as above!
// that is, use t_nam, t_val, and t_cst as virtual pointers to the variables i actually want to read
// trying to avoid this:
if t_idx==0 then
t_name=_tool_0
t_cost=_c_tool_0
t_valid=_v_tool_0
//elseif
//...... repeat for every tool
// ..... maintain this code anytime i update the set of tools supported in-game
end
end
end
Anyone know if this is possible?
If not I suppose I'll post a feature request... but it feels really similar to existing PulpScript mechanisms already - we already switch between strings and identifiers elsewhere like when we call a handler or refer to a tilename... so i'm hoping it can already be done
-bit