Jump to content
XenoTools

How To Use A "state" In Java Scripts

Recommended Posts

Someone asked me, so here

//Imports herepublic class ScriptName extends Script {	private static enum BotState = {		STATE_1,		STATE_2,		STATE_3,		STATE_4,		STATE_5	};	private BotState state;	public int onLoop() {		state = setState(); // Method to figure out which state the bot is in		return handleState(state);	}	/***************************************************************	*  Method BotState setState() 	*  returns ENUM - BotState	*  Use this method to calculate the state	*  Such as, if the players inventory is full	*  return BotState.BANKING	****************************************************************/	private BotState setState() {		// Stuff here		return BotState.STATE_5;	}	/***************************************************************	*  Integer handleState 	*  returns integer	*  Use this method to function	*  according to which state the script is in/	*  Example: if STATE_1, RETURN 1000;   (If the bot is in state_1, wait for a second. If not, look for another	*  state.	****************************************************************/	private int handleState(BotState state) {		switch(state) {			case STATE_1:				//code				return 1000; // Wait time before next onLoop()			case STATE_2:				//code				return 710; // wait time before next onLoop()		}	}}
Edited by XenoTools
  • Like 1
Link to comment
Share on other sites

 

Good job, could be more details or examples. My AIO scripts use something like this but a bit different this can make the code more efficient and cleaner.

 

Really isn't much to show, if you get it you get it, if you don't you don't.

It's very basic scripting and anybody who understands a hello world program using a switch would understand this. /:

EDITED with slight comment adjustments

Edited by XenoTools
  • Like 1
Link to comment
Share on other sites

  

Really isn't much to show, if you get it you get it, if you don't you don't.

It's very basic scripting and anybody who understands a hello world program using a switch would understand this. /:

EDITED with slight comment adjustments

Well not everyone knows how to use Enums, just saying anyway good job now it looks better :))

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...