IDE support / mock context?


#1

The code editor in cc is pretty decent, but I prefer to write my code in an IDE (specifically PyCharm since I code python in my day-job). I’m writing in javascript, since my whole excuse for playing is to refresh / improve my javascript. Inside the IDE, hero is not defined, which causes all kinds of spurious warnings. Is there a way to define hero at the top of my script so that

  1. I can copy / paste into the CC script window and execute without changing anything
  2. I can reference a real hero object (or at least a reasonable mock)

I’m thinking something like:

// import the Hero code from somewhere, but where and how?
if (hero === undefined) {
    var hero = new Hero();
}

#2

@ahammond You lost me a bit on this one. How is the IDE helping you code?

I don’t have a example of the hero object, but you could always start with a skeleton framework and build as you go.

Any equipment you pick up along the way will allow you access to more hero functions so you can add stubs to them as you go. The code itself will also give you more hints for this. But you won’t be just building a hero object, you will need to create objects for the other NPC’s as well as Enemies, Spells, and objects etc in the game.

[Javascript]

// Stub for game objects
var hero = {};
hero.moveUp = funciton() {
};
hero.health = 20;
// Insert game code below

As a side note for personal use, I can see where creating these objects could be good for short hand notes when I am working out more complex algorithms for the multiplayer levels and levels one can repeat.


#3

@Harry_the_Wanderer How does an IDE help me code? I hardly know where to begin. Static error checking, code style enforcement, git integration, class / method introspection and dynamic referencing. Uh… the list just goes on, almost endlessly. Try it, you’ll never go back.

As far as “write your own mock framework”, I’m thinking there has to be a better answer. The API must, I assume, be visible to the internet?


#4

I believe is the Git repository. I couldn’t help you further than that as I haven’t yet looked at the code. As far as an API, I don’t know if they have one as part of the code base. But I guess that would also depend on how one defines what an API is.

As far as the IDE goes, what I was trying to get at was if you really needed to work in one, or if you were just looking to use the IDE as a manner of preference.

If you get it working, I would be interested to now your steps to do so.


#5

I’m currently using PyCharm and copy-pasting from there to the code execution window in the game. It’s better than coding directly in the game window for the aforementioned reasons and spurious errors because hero isn’t defined while unfortunate are certainly not show-stoppers. I’ll spend a little more time on this next weekend, if the wife and kids leave me any downtime.


#6

Usually linters provide a way to specify a variable as global, so you could try checking your IDE’s documentation for that.

For example with ESLint and JSHint you can add

/* global hero */

to the top of your file.