- Joined
- Mar 13, 2018
- Messages
- 7,299
- Thread Author
- #1
I posted about this on slack, but I'll make a proper report here. I was trying to use ManagedProperties to store usage info for a lite version of a bot when I found that most of the functions bugged out in a weird way.
For example, this does work. It stores the property "taco" and returns "one":
But if you do this (note the change in onStart), not only does onStart's print return null but also onStop's setProperty fails & returns null:
HOWEVER, I looked into it even more, and if you add to the very beginning of onStart()
Then suddenly the second code snippet works and propertyNames() returns the expected data, even though the property "init" doesn't matter to us.
If I were to take a guess, it seems like there's some initialization code that exists in getProperty() and doesn't exist in most of the other functions, because right now it's necessary to call getProperty() before using any of the other functions. If you don't call it, the other functions return null/empty.
For example, this does work. It stores the property "taco" and returns "one":
Code:
public class TestBot extends LoopingBot {
@Override
public void onStart(String... arguments) {
String t = getSettings().getProperty("tacos");
System.out.println(t);
}
@Override
public void onLoop() {
}
@Override
public void onStop() {
Object t = getSettings().setProperty("tacos", "one");
System.out.println(t);
}
}
But if you do this (note the change in onStart), not only does onStart's print return null but also onStop's setProperty fails & returns null:
Code:
public class TestBot extends LoopingBot {
@Override
public void onStart(String... arguments) {
Enumeration<?> t = getSettings().propertyNames();
System.out.println(t);
}
@Override
public void onLoop() {
}
@Override
public void onStop() {
Object t = getSettings().setProperty("tacos", "one");
System.out.println(t);
}
}
HOWEVER, I looked into it even more, and if you add to the very beginning of onStart()
Code:
getSettings().getProperty("init");
Then suddenly the second code snippet works and propertyNames() returns the expected data, even though the property "init" doesn't matter to us.
If I were to take a guess, it seems like there's some initialization code that exists in getProperty() and doesn't exist in most of the other functions, because right now it's necessary to call getProperty() before using any of the other functions. If you don't call it, the other functions return null/empty.