Closed saltlakrits closed 4 years ago
Try using the fix-build branch of screeps-game-api. Apparently there's some confusing stuff happening with stdweb atm.
To do this, replace the screeps-game-api = "0.6"
line in your Cargo.toml with the following :
screeps-game-api = { git = "https://github.com/rustyscreeps/screeps-game-api.git", branch = "fix-build" }
Please tell us if it works. We might need to update the starter script.
@saltlakrits The branch has been merged, so now you'd need to use master
instead of fix-build
.
I believe we'll make a release as soon as the factory stuff has been merged.
Apologies for being slow to get back, I had no chance to sit down and try this stuff. After trying to build the starter example again with the master branch of screeps-game-api, I get another couple of errors, but this looks like the starter code is using methods that no longer exist perhaps?
error[E0599]: no method named `carry_total` found for type `screeps::objects::Creep` in the current scope
--> src/main.rs:72:22
|
72 | if creep.carry_total() == creep.carry_capacity() {
| ^^^^^^^^^^^
error[E0599]: no method named `carry_capacity` found for type `screeps::objects::Creep` in the current scope
--> src/main.rs:72:45
|
72 | if creep.carry_total() == creep.carry_capacity() {
| ^^^^^^^^^^^^^^
error[E0599]: no method named `carry_total` found for type `screeps::objects::Creep` in the current scope
--> src/main.rs:76:22
|
76 | if creep.carry_total() == 0 {
| ^^^^^^^^^^^
error: aborting due to 3 previous errors
I sadly couldn´t check if my solution is working because somehow my rustc is compiling endlessly. I´m not sure if that issue is related to my changes but that´s what i found.
I ran into the same problem and after a bit of digging in the git history i found the following commit: https://github.com/rustyscreeps/screeps-game-api/commit/aa545b48f8240a493e4abd5e14f219aebbee3841
The api was changed due to deprecation, so the syntax changed from this:
if creep.memory().bool("harvesting") {
if creep.carry_total() == creep.carry_capacity() {
creep.memory().set("harvesting", false);
}
} else {
if creep.carry_total() == 0 {
creep.memory().set("harvesting", true);
}
}
to this:
if creep.memory().bool("harvesting") {
if creep.store_free_capacity(ResourceType::Energy) == 0 {
creep.memory().set("harvesting", false);
}
} else {
if creep.store_used_capacity(ResourceType::Energy) == 0 {
creep.memory().set("harvesting", true);
}
}
You also need to change line 4 to include ResourceType like this:
use screeps::{find, prelude::*, Part, ReturnCode, RoomObjectProperties, ResourceType};
Also you don´t need to use the git version anymore since version 0.7.0 of screeps-game-api released.
Now I got this
Compiling screeps-game-api v0.7.0
Compiling screeps-starter-rust v0.0.0 (/home/saltlakrits/Code/Screeps/Rust)
error[E0308]: mismatched types
--> src/main.rs:72:42
|
72 | if creep.store_free_capacity(ResourceType::Energy) != 0 {
| ^^^^^^^^^^^^^^^^^^^^
| |
| expected enum `std::option::Option`, found enum `screeps::constants::types::ResourceType`
| help: try using a variant of the expected type: `Some(ResourceType::Energy)`
|
= note: expected type `std::option::Option<screeps::constants::types::ResourceType>`
found type `screeps::constants::types::ResourceType`
error[E0308]: mismatched types
--> src/main.rs:76:42
|
76 | if creep.store_free_capacity(ResourceType::Energy) == 0 {
| ^^^^^^^^^^^^^^^^^^^^
| |
| expected enum `std::option::Option`, found enum `screeps::constants::types::ResourceType`
| help: try using a variant of the expected type: `Some(ResourceType::Energy)`
|
= note: expected type `std::option::Option<screeps::constants::types::ResourceType>`
found type `screeps::constants::types::ResourceType`
error: aborting due to 2 previous errors
With the way we've written the HasStore
APIs, store_free_capacity
takes an Option<ResourceType>
. Specifically, you'll want to use store_free_capacity(Some(ResourceType::Energy))
- or probably, store_free_capacity(None)
, to account for any non-energy resources.
With #16, the starter code has also been updated to do this.
Compiled without issue! Cool beans, although I think I need a far better grasp on Rust before I can get anywhere, I find the documentation a little hard to follow. Thanks for resolving the issues!
Not sure if I'm doing something wrong or not, because I am still very new to Rust, Cargo, Screeps and transpiling, but I can't get anything to compile. I get about 33 errors all (seemingly) relating to the same thing. If required I can paste the whole thing.