![]() |
#16 | |
Corkscrew Chainsaw!!!
|
![]() Think of Table as an integer array. However, while a normal integer array can only use indexes 0 - 8191, Table can use any integer (even negatives). If you define the table as local, it acts just like a local integer array. If you define it as global, it acts like a global integer array.
__________________Hmm... hopefully this will help: ![]()
|
|
![]() |
![]() |
Sponsored Links - Login to hide this ad! |
|
![]() |
#17 |
User
Join Date: Feb 2006
Posts: 172
![]() ![]() |
![]() Ah, I see, thanks :)
So, under 'normal' circumstances, a local Table, and a single key should do fine? Would there be any problem with using the same key in separate triggers, if t is local to each? |
![]() |
![]() |
![]() |
#18 | |
Procrastination Incarnate
Development Director
|
![]() Quote:
BTW, Trollz, that's not what your script would actually output. |
|
![]() |
![]() |
![]() |
#19 |
Free Software Terrorist
Technical Director
|
![]() All right I updated it, it is less pure but a little better, something like this requires to cover all gamecache usage else it is not a good idea to implement it along with other gamecaches, the difference is that you can use HandleTable and StringTable to have tables with different key types.
__________________ |
![]() |
![]() |
![]() |
#20 |
master of fugue
Join Date: Jun 2007
Posts: 2,453
![]() ![]() ![]() ![]() ![]() |
![]() I think you should not use macro parameter for mission key.
__________________Better instead pass it to a constructor. I misread it, thought $key$ was mission and it is I2S(this), nwm EDIT: Why you called this table when it is only a nice way of doing gamecache? Why not simply call it Cache? Last edited by cohadar : 07-06-2008 at 10:20 PM. |
![]() |
![]() |
![]() |
#21 |
User
Join Date: Apr 2007
Posts: 356
![]() |
![]() is this the same as the Table trigger inside your xe system?
__________________ |
![]() |
![]() |
![]() |
#22 |
Free Software Terrorist
Technical Director
|
![]() Table is just used by one of the xe samples, it is not part of xe.
__________________ |
![]() |
![]() |
![]() |
#23 |
User
Join Date: Apr 2007
Posts: 356
![]() |
![]() ok, so that means this table cant be a substitute for xe's table
__________________ |
![]() |
![]() |
![]() |
#24 | |
Free Software Terrorist
Technical Director
|
![]() Quote:
The Table library used by stormy dreams is an old version of this thing, you can safely upgrade. |
|
![]() |
![]() |
![]() |
#26 |
Lackadaisically Absent.
Respected User
|
![]() So, I needed a Table to store reals, and I realized that I would have to modify your library to do so. I ended up with this, and it seems to work:
__________________![]() library Table initializer init //*************************************************************** //* Table object //* ------------ //* //* set t=Table.create() - instanceates a new table object //* call t.destroy() - destroys it //* t[1234567] - Get value for key 1234567 //* (zero if not assigned previously) //* set t[12341]=32 - Assigning it. //* call t.flush(12341) - Flushes the stored value, so it //* doesn't use any more memory //* t.exists(32) - Was key 32 assigned? Notice //* that flush() unassigns values. //* call t.reset() - Flushes the whole contents of the //* Table. //* //* call t.destroy() - Does reset() and also recycles the id. //* //* If you use HandleTable instead of Table, it is the same //* but it uses handles as keys, the same with StringTable. //* //*************************************************************** //============================================================= globals private constant integer MAX_INSTANCES=8100 //400000 //========================================================= private gamecache gc endglobals private struct GTable[MAX_INSTANCES] method reset takes nothing returns nothing call FlushStoredMission(gc,I2S(this)) endmethod private method onDestroy takes nothing returns nothing call FlushStoredMission(gc,I2S(this)) endmethod endstruct //Hey: Don't instanciate other people's textmacros that you are not supposed to, thanks. //! textmacro Table__make takes name, type, key struct $name$ extends GTable method operator [] takes $type$ key returns integer return GetStoredInteger(gc,I2S(this),$key$) endmethod method operator []= takes $type$ key, integer value returns nothing call StoreInteger(gc,I2S(this),$key$, value) endmethod method flush takes $type$ key returns nothing call FlushStoredInteger(gc,I2S(this),$key$) endmethod method exists takes $type$ key returns boolean return HaveStoredInteger(gc,I2S(this),$key$) endmethod endstruct //! endtextmacro private function H2I takes handle h returns integer return h return 0 endfunction //! runtextmacro Table__make("Table","integer","I2S(key)" ) //! runtextmacro Table__make("StringTable","string","key" ) //! runtextmacro Table__make("HandleTable","handle","I2S(H2I(key))" ) //Pyrogasm Stuff: struct RealTable extends GTable method operator [] takes real key returns real return GetStoredReal(gc,I2S(this),R2S(key)) endmethod method operator []= takes real key, real value returns nothing call StoreReal(gc,I2S(this),R2S(key), value) endmethod method flush takes real key returns nothing call FlushStoredReal(gc,I2S(this),R2S(key)) endmethod method exists takes real key returns boolean return HaveStoredReal(gc,I2S(this),R2S(key)) endmethod endstruct //============================================================= // initialize it all. // private function init takes nothing returns nothing call FlushGameCache(InitGameCache("libtable.gc")) set gc=InitGameCache("libtable.gc") endfunction endlibrary But anyway: I think that you should add a "RealTable" to this, as it is potentially useful to others, let alone myself. |
![]() |
![]() |
![]() |
#27 |
Free Software Terrorist
Technical Director
|
![]() I never thought of that mostly because storing anything other than integer is kind of lame?
__________________What's that odd situation in which you ONLY need a real value and nothing integral? |
![]() |
![]() |
![]() |
#28 |
I blink, therefore I am.
Join Date: Sep 2006
Posts: 1,812
![]() ![]() ![]() ![]() |
![]() I agree that storing anything other than an integer is lame (cause you should be using structs for handles) but I also needed a RealTable for one of my systems.
__________________I wanted to use it for storing the widths of chars, and storing as an integer and dividing by some constant seemed like a waste of over-head. |
![]() |
![]() |
![]() |
#30 | |
Procrastination Incarnate
Development Director
|
![]() Quote:
|
|
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
|