- Joined
- Oct 18, 2007
- Messages
- 930
You Need:
Example
How an indexer works
- The newest version of JNGP
- Common vJass and Jass experience
ReadmeThis is a simple example of how you can use an indexer system. You can do alot more of the one thing i show you here.
If you find things that i need to add then please tell
And sorry for my english, from norway >.<
The struct
For adding a struct to the loop you need to allocate a struct then add it to the indexer
Example
JASS:
struct SomeStruct
// [Your Strut Members]
// Just a random struct member used for an example
integer x = 0
// You need 2 static members( You can use 2 globals, but I find using static members a lot easier ):
static SomeStruct array Index // The array that stores the struct
static integer Total // The array that keeps track of how many structs there are in use
// Lets say we doing some stuff for a counting sys, we use this method
static method Loop takes nothing returns nothing
// Both of theese locals are needed for this loop
local SomeStruct dat
local integer i = 0
loop // Loop for the struct
exitwhen i >= dat.Total // The loop will end when all structs have passed the loop func
set dat = dat.Index[i] // Setting the local struct dat to the stored struct in the static metmber Index
// Lets say that if i < 10 it will do stuff
if dat.x < 10 then
set dat.x = dat.x + 1
else
[Your actions on end]
// Just some random call, you dont need this
call BJDebugMsg("10 reached!")
// destroying the struct
call dat.destroy()
// Recycling the indexer system
set dat.Total = dat.Total - 1
set dat.Index[i] = dat.Index[dat.Total]
// If you dont set the i to i - 1 when destroying a struct the next struct will not be looped, so it is very important
set i = i - 1
endif
set i = i + 1
endloop
// This could be useful for looping functions
// If number of structs is equal to 0 then the timer will stop.
if dat.Total == 0 then
call PauseTimer(SomeTimer)
endif
endmethod
endstruct
For adding a struct to the loop you need to allocate a struct then add it to the indexer
Example
JASS:
static method Start takes nothing returns nothing
local SomeStruct dat = SomeStruct.allocate()
[Do Something]
// If you are doing a timer loop then this could be useful
// If the total amount of structs looping is equal to 0 a Timer will start
// Note: This have to be done before adding the struct to the indexer
if dat.Total == 0 then
call TimerStart(SomeTimer, 0.1, true, function SomeStruct.Loop)
endif
// Adding the struct to the indexer system
set dat.Index[dat.Total] = dat
// Setting the total amount of structs in loop to Total + 1
set dat.Total = dat.Total + 1
endmethod
How an indexer works
JASS:
1 2 3 4 5 // initial arrangement
- 2 3 4 5 // struct 1 ends
5 2 3 4 - // move struct 5 to struct 1's place and decrease the total number of structs running
5 - 3 4 - // struct 2 ends
5 4 3 - - // repeat
5 4 - - - // struct 3 ends
4 - - - - // struct 5 ends
- - - - - // struct 4 ends, no structs running and timer stops
Last edited: