- Joined
- Aug 14, 2005
- Messages
- 49
Hi!
I'm currently in the process of rewriting my entire map in Wurst (yes, I think it's that awesome. My map is a GUI disaster, so this was urgently needed).
Now, I have a lot of situations where I need to do something whenever someone buys an item. In GUI, I did this with (a lot of) triggers that ran whenever someone bought an item and then simply using a condition to check for "the right item".
In Wurst, I had the idea of simply using a HashMap where I store all the items as keys and the function to be executed as corresponding values. Then, this would only need one trigger: If someone buys an item, look up in the hashmap which function to run for this item and execute it.
Obviously, writing this:
Doesn't work. After some looking around, I tried:
But here I get an error, saying: "Type parameters can only be bound to ints and class types, but not to code. You can provide functions codeToIndex and codeFromIndex to use this type with generics."
I tried looking this up, but I couldn't find information on these functions (codeToIndex and codeFromIndex) anywhere.
My current solution is to try and implement a kind of class wrapper
And simply write lots of (static?) classes that will wrap this with a corresponding function and then simply use this as my generic type for the HashMap. But before I do that, I was wondering if I am going at this all wrong and if there is either a smarter / already implemented way of achieving the same thing or how I can implement this codeToIndex and codeFromIndex
Thanks for reading and all the best
I'm currently in the process of rewriting my entire map in Wurst (yes, I think it's that awesome. My map is a GUI disaster, so this was urgently needed).
Now, I have a lot of situations where I need to do something whenever someone buys an item. In GUI, I did this with (a lot of) triggers that ran whenever someone bought an item and then simply using a condition to check for "the right item".
In Wurst, I had the idea of simply using a HashMap where I store all the items as keys and the function to be executed as corresponding values. Then, this would only need one trigger: If someone buys an item, look up in the hashmap which function to run for this item and execute it.
Obviously, writing this:
Code:
var item_functions = new HashMap<item, function>
Doesn't work. After some looking around, I tried:
Code:
var item_functions = new HashMap<item, code>
But here I get an error, saying: "Type parameters can only be bound to ints and class types, but not to code. You can provide functions codeToIndex and codeFromIndex to use this type with generics."
I tried looking this up, but I couldn't find information on these functions (codeToIndex and codeFromIndex) anywhere.
My current solution is to try and implement a kind of class wrapper
Code:
abstract class Function
abstract function execute()
And simply write lots of (static?) classes that will wrap this with a corresponding function and then simply use this as my generic type for the HashMap. But before I do that, I was wondering if I am going at this all wrong and if there is either a smarter / already implemented way of achieving the same thing or how I can implement this codeToIndex and codeFromIndex
Thanks for reading and all the best