Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

DragonRuby Game Toolkit

An intuitive 2D game engine. Fast, cross-platform, tiny, hot loaded. · By DragonRuby

How do you define user defined variables?

A topic by zonemaster created Jun 23, 2019 Views: 458 Replies: 4
Viewing posts 1 to 5
(2 edits)

in other words if I want to define a variable called - timer?

timer ||= 300

say i have a sprite randomly appearing on the screen and moving to a different location after timer == 300 (5 seconds)


#move sprite to a random location after 5 seconds
  if args.game.tick_count % 300 == 0
    args.game.x = rand * 1279
    args.game.y = rand * 719
  end

this seems to do what is expect move the sprite after 5 seconds to a random position but i want to do this:

#move sprite to a random location after 5 seconds
  if args.game.tick_count % timer == 0
    args.game.x = rand * 1279
    args.game.y = rand * 719
  end

so when you click the sprite it increasingly gets harder by decreasing the time (moves faster each time you click the mouse)

I hope you get what I am trying to say here. lol


oh BTW when you recieve an error it doesn't make any sense at all (doesn't point to the line where the error occured) it's some random stuff that makes no sense whatsover in the console. this really needs proper error handling.

If you are using the 'entities', you could do something like:
=========
game.full_timer = 300
game.moving_thing = game.new_entity(
  :moving_thing,
  x: rand * 1279,
  y: rand * 719,
  timer: game.full_timer
)
=========
Then in your tick:
========= game.moving_thing.timer -= 1
if game.moving_time.timer <0
  game.moving_thing.x = rand * 1279
  game.moving_thing.y = rand * 719
end
=========
Then if your mouse click is detected on the `moving_thing` reduce game.full_timer to something smaller.

I guess, but since this SDK lacks the proper documentation, I have no idea what you are talking about.

I guess I will come back in a few months and see how this is coming along, right now this is not as 'dirt simple' as claimed and the syntax debugging is non-existent so finding simple errors is practically impossible (at least for me)

I would like to see if possible:

an actual IDE for loading/saving/debugging projects

professional documentation (examples and samples are okay but when they are not documented how do you learn the language)

proper debugging and error handling

more tutorials that actually show you how these commands are carried out.

I wil be back sometime in the future, maybe. :(

Developer

Zonemaster, take a look at the sample apps. There are a ton of useful real-world "recipes" in there. The next release will streamline these sample apps further.

args.game.timer ||=300
  if args.game.tick_count % args.game.timer == 0
    args.game.x = rand * 1279
    args.game.y = rand * 719
    args.game.timer -= 10
  end