0

I'm writing a Rust starter package for other programmers to interface with a game (write bots for it), and I'm not quite sure how to accomplish a specific task.

At the beginning of initialization, each bot is sent some information that persists throughout the entire game. A different set of information is then sent every frame of the game. When I return the game state every frame, I'd like to reset the values given during initialization; that way, if a user edits the values they were sent during initialization they won't persist

For consistency with the starter packages for other languages, the values sent during initialization are encapsulated in an object with the values sent every frame. I think they do belong in the same object, as they're really different aspects of the same thing, but if necessary I'm willing to change that.

I'd like to keep the starter package API as clean as possible (and consistent with the other language starter packages) and not add any functions beyond getInit, sendInit, getFrame, and sendFrame.

In the other starter packages, I simply cache the values sent during initialization in a private global variable, but the only way I can see how to do that in Rust would be to use global mutables, which also seem to be against the Rust philosophy.

How would an experienced Rustacean do this?

  • I've marked this as a duplicate, but really it seems [too broad](/help/dont-ask) and [off topic](/help/on-topic). Perhaps you might want to ask on the [Rust users forum](https://users.rust-lang.org/) or [subreddit](https://www.reddit.com/r/rust). – Shepmaster Jul 13 '16 at 21:34
  • 1
    This could be an interesting problem, but is still very unclear by your description. In fact, I'm wondering why you need a global variable for that. Could you show a specific (yet minimal) example of the API in another language (like C or C++)? – E_net4 Jul 13 '16 at 21:37

0 Answers0