Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

RPG in a Box

Bring your stories and ideas to life! · By Justin Arnold

A few scripting questions

A topic by lectronice created Nov 19, 2016 Views: 115 Replies: 4
Viewing posts 1 to 5

Hi there!

So I've been diving into scripts, mostly for dialogues, and opening / closing things like doors, curtains, chests, etc. And it works well so far, but there are a few things I don't fully understand, so here come a few questions :)

  • There's possibly a bug with global properties (or booleans). For example, I'm checking this at the beginning of a dialogue: global.property["chest2_empty"] == false to launch a dialogue node, and the dialogue never starts. But if I use global.property["chest2_empty"] != true, it works fine. Is it normal?
  • In a dialogue, is the default condition self.property["visited"] == "yes" meant to launch the following node if the dialogue has never been started before? I didn't manage to make it work (that's why I ended up using global properties).
  • There are booleans and strings, but don't see a way to use integers. Do you plan to add this in the future? I'd probably need something like a way to increment / decrement some global properties to keep track of characters relationships and similar things.
  • Also, something useful would be some kind of log or debugger to track properties during the game. Or is there a way to do that with the developer console? Or to print / watch properties in the Godot window?
And that's about it for now :)

Hello!

There's possibly a bug with global properties (or booleans). For example, I'm checking this at the beginning of a dialogue: global.property["chest2_empty"] == false to launch a dialogue node, and the dialogue never starts. But if I use global.property["chest2_empty"] != true, it works fine. Is it normal?

I think I know what is going on here. If a property has never been set to anything before, it's going to have a default value of "null" as opposed to false, so the comparison evaluates to false. That would explain why the inverse does work (null != true). That could definitely be confusing, so I may change it to work like some other languages where basically anything besides a true value (null, non-boolean value) is considered false by default if used in a conditional expression.

In a dialogue, is the default condition self.property["visited"] == "yes" meant to launch the following node if the dialogue has never been started before? I didn't manage to make it work (that's why I ended up using global properties).

This is kind of misleading as well. It wouldn't launch the following node unless the "visited" property had been previously set to "yes" elsewhere. It was just an arbitrary condition I defaulted it to way back when I first started working on dialogue, so I will change this to something that would make more sense.

There are booleans and strings, but don't see a way to use integers. Do you plan to add this in the future? I'd probably need something like a way to increment / decrement some global properties to keep track of characters relationships and similar things.
Yes, I will be adding integers (and arithmetic expressions for adding, subtracting, etc.) at some point - probably sooner rather than later since they will be useful to have. First step will probably be getting to where you can do something like this:
set_global_property("test", global.property["test"] + 1)
Also, something useful would be some kind of log or debugger to track properties during the game. Or is there a way to do that with the developer console? Or to print / watch properties in the Godot window?
There is currently one way you can do this using the placeholder expression functionality thatI recently added along with the Display Message function. If you put the code below into the developer console it will pop up a message and ${global.property[\"test_message\"]} will be replaced with whatever value is in the "test_message" property.
display_message("The value of the test property is: ${global.property[\"test_message\"]}")

Note that you need to escape the double quotes with a backslash before each since they are inside of a string. Hopefully that helps some! The placeholder expression can reference both global properties and entity properties (and more eventually).

Thanks for the questions!

Thanks! This == / != logic is indeed totally logical, I thought declaring properties wasn't needed. And this Display Message trick will be very useful :)

Hi!

I'm trying to set up a script to make an entity change its frame each time the player clicks it. I've come up with this:

if self.property["state"] == 0 then
  play_animation(self, "frame1");
  set_entity_property(self, "state", self.property["state"] + 1)
else
  if self.property["state"] == 1 then
    play_animation(self, "frame2");
    set_entity_property(self, "state", self.property["state"] + 1)
  else
    if self.property["state"] == 2 then
      play_animation(self, "frame3");
      set_entity_property(self, "state", self.property["state"] + 1)
    else
      if self.property["state"] == 3 then
        play_animation(self, "frame4");
        set_entity_property(self, "state", self.property["state"] + 1)
      end
    end
  end
end

And I get this error:

SCRIPT ERROR: eval Invalid operands 'String' and 'int' in operator '=='.
    At: res://parser/relop_bexp.gd:34

However, if I use global properties, like below, everything works as expected.

if global.property["state"] == 0 then
  play_animation(self, "frame1");
  set_global_property("state", global.property["state"] + 1)
else
  if global.property["state"] == 1 then
    play_animation(self, "frame2");
    set_global_property("state", global.property["state"] + 1)
  else
    if global.property["state"] == 2 then
      play_animation(self, "frame3");
      set_global_property("state", global.property["state"] + 1)
    else
      if global.property["state"] == 3 then
        play_animation(self, "frame4");
        set_global_property("state", global.property["state"] + 1)
      end
    end
  end
end

Am I missing something, or is there a problem with local properties integers?

Looks like I forgot to update some logic involved in retrieving a property for an entity which was causing an uninitialized property to not properly default to zero if used within an arithmetic expression. I did make the change originally for global properties which is why it was working for those. I am releasing an update here shortly and it will include a fix for this. :)