Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - DementedKirby

#16
Development / Re: Trouble making a bridge.
July 30, 2015, 07:17:55 PM
Make the entire part you want in low layer then above it make the exact same tiles in intermediate layer. That way when you change from one to the other, the hero appears accordingly. I think your error is more graphical than "scriptical".
#17
Okay, so thanks to several members (particularly Maxs) I've been able to do some steady progress with items. I think I'm getting the hang of how all of this works. Here's an example:

I'm working on making the Book of Mudora. So far I've been able to get the hero to take the book out and read it with this code:

function item:on_using()
   item:get_map():get_entity("hero"):set_animation("book")
   game:start_dialog("book.test", nil, function ()
   item:set_finished()
   end)
end


However, we all know that the book only works in front of places written in Hylian script in order to translate. So what I'd really like the code to do is to just give an error sound when used in an inappropriate place. Simple enough. I can simply do that instead of doing what's done in the previous function. However, I do want it to be used when translating Hylian text. Now, with items, you can use them when in contact with certain npcs thanks to 'item:on_npc_interaction_item(npc,item)'. So this is what I came up with:

local sign = item:get_map():get_entity():get_name()

function item:on_npc_interaction_item(sign,item)
   if sign == "ForestSign" then
      item:get_map():get_entity("hero"):set_animation("book")
      game:start_dialog("book.translation", nil, function ()
      item:set_finished()
      end)
   end
end


However, I get this error:
QuoteError: In items/book: [string "items/book.lua"]:4: bad argument #1 to 'get_map' (sol.item expected, got no value)

So I'm pretty lost as to what to do, lol. As long as I erase the 'sign' variable declaration and the function that interacts with npcs, I get no error. So I know it's in that part of the script.
#18
Development / Re: Assigning Hotkeys to Items
July 30, 2015, 05:47:23 AM
Ah, I see. Well, I guess I'm just gonna have to do this with map scripts then in the mean time. Thanks for clearing up what limitations I could have with this!
#19
Development / Re: Assigning Hotkeys to Items
July 30, 2015, 05:09:26 AM
But then the variable game would have to be declared somewhere, no? Oh, and the book.lua I was referring to isn't the item script; it's a lua I made in the same directory so that sol.main.load_file("book") and sol.main.do_file("book") would access them. The accessing part isn't the problem. It happens just fine. It's what happens when they lua file is called that I get the error. I know the lua is called and accessed because the error comes from book.lua, which means it's being read. I will check your suggestion in the mean time to see if maybe that's the problem.
#20
Oops! Sorry, I didn't know that was something to be considered. Is there a link where there's a list of things that will be considered or planned for a future release? That way I won't ask again for something already in the works.
#21
Development / Assigning Hotkeys to Items
July 30, 2015, 02:16:31 AM
Okay, so I'm testing and I want to be able to quickly go to items - more specifically, hit a key on the keyboard and the same effect as using the item occurs - regardless if the hero has the item or not. I've got the key to work. What I'm doing is using

-- Keyboard testing
  function game:on_character_pressed(key)
   if key == "q" then
      sol.main.load_file("book")
      sol.main.do_file("book")
   end
  end

inside of quest_manager.lua. The book.lua it's opening is just this:

local item = ...
local game = item:get_game()

item:get_map():get_entity("hero"):set_animation("book")
game:start_dialog("book.test", nil, function()
item:set_finished()
end)

and I get the following error:
QuoteError: In book: [string "book.lua"]:2: attempt to index local 'item' (a nil value)
This is an error I keep getting constantly and I really have no idea why. Apart from this error everything else seems to be working. I just gotta overcome this obstacle.
#22
Development / Re: Trouble making a bridge.
July 30, 2015, 01:16:31 AM
Remember that if you change the hero's layer and not the tile's layer, the hero may disappear of strange things may happen if you don't have any corresponding tiles above or below. How about using dynamic layers that appear or disappear as you traverse the sensor?

I'm pretty sure that with just having tiles beneath the bridge in low layer and making the bridge intermediate layer you should get the effect that you want. However, you need a stairs type entity to traverse between layers in an easy manner.

However, if you're dead set on moving up or down a layer forcefully, you could use the sensor to simply change the layer. An example:
function layer_change:on_activated() -- layer_change is a sensor
   local x, y, layer = hero:get_position()
   if layer == 0 then
      hero:set_position(x,y,0)
   else
      hero:set_position(x,y,1)
end


That should work. You could use that on an area on the map that looks like you're going up or down a hill to visualize the change of layer.

EDIT:
To make the transition smoother, you could dedicate one sensor each per layer change. That way you can make sure it happens smoothly.
#23
Ha! Success! You, sir, have just been the equivalent of getting handed the Fierce Deity Mask at the beginning of the game - regardless the Zelda game, lol. Now, I just have to see why it won't work in my own game, lol. Lemme try and do the exact same thing in it. Thanks!
#24
Ok, got it, here's the error:
Error: In on_using: [string "items/book.lua"]:11: attempt to index global 'hero' (a nil value)
#25
Thanks for explaining the errors of my code! You've been really helpful and I appreciate it (now that you mention the error.txt, this game in particular isn't generating an error.txt file in its folder after closing the game window so that maybe a whole other problem altogether...) Yet, despite literally just copy/pasting your code, it's still not working but for some reason,  The hero still freezes and doesn't do absolutely anything else after I use the item for a first time. Oh, and yeah, the book animation is one I created in the hero folder of the entities part of the quest. It's literally only one frame (regardless of direction; all four directions is the same sprite) and it's called "book".

UPDATE:
The problem is changing the hero's animation. I made the line into a comment and everything else worked. Meaning that I can't simply use that command to change the hero's graphic as he's using the item? That feels a bit counter-intuitive... How then would I be able to program other items like the Hammer and Net? Link's gotta change graphics when using these items. I've been reading the documentation and it talks about set animations already coded into Solarus but if I'm able to make new animations I should be able to access them the same way, no?
#26
Actually, to get it to work is a lot easier than that. All I have to do is get the item to work when the hero is swimming. But with everything you told me I guess I have an idea:

If hero is not swimming and item is pressed then an error sound occurs else
If do what the item is supposed to do.

Actually, the difficulty in making an Iron Boots comes not from coding but level design. All you have to do is make sure that wherever you have deep water, it's on the intermediate level and the "floor" beneath the water be low layer. All the Iron Boots do is send the hero to the bottom layer (beneath the water). What I'm doing is making the hero speed 44 (half of normal), maintaining the same x & y, and just changing the layer to 0. That makes it appear that you're slow because of moving underwater. After that, a boolean is stored. When that Boolean is true and the boots are used again, all you do is the same exact thing just change the hero to layer 1 and store the Boolean as false. And he's back to the surface of the water swimming. Super easy. All I have to do is make sure that the hero can only use the boots when swimming - and to use them at all when swimming, lol. So basically, what the item does is this:

--when item is used and hero is neither swimming nor the iron_boots bool is true:
sol.audio.play_sound("error") else
--when item is used if swimming state is true:
hero:set_walking_speed(44)
local x, y, layer = hero:get_position()
hero:set_position(x,y,0)
game:set_value("iron_boots",true) else
--when the bool is true and the item is used:
hero:set_walking_speed(88)
local x2, y2, layer2 = hero:get_position()
hero:set_position(x2,y2,1)
game:set_value("iron_boots",false) else
--this makes the hero appear to be walking underwater (you have to use the underwater tile that's transluscent)


That's the basic concept. Again, I got it to work with sensors placed on the water to make the hero walk underwater and then underwater to return the hero swimming to the surface. It's as simple as changing the hero's layer. Which is why the difficulty is in the level programming. You may want to make the hero teleport to a "new place" that represents what's the beneath the water's surface or simply make the bottom of the water and have it show through a translucent water tile. The possibilities are endless. So again, all I have to do is get the item to work when the hero is swimming.

What I was able to test with the sensor (each sensor only changed the layer) is that swimming is dependent on the layer. Changing the layer when in water or underwater makes the hero swim or walk underwater depending on the layer of the water. Doesn't that blow your mind? Think of all the possibilities of the douchiness of a more difficult Water Temple? That's what I'm currently designing right now, lol.

UPDATE:
Here's what I'm gonna try:
function game:on_command_pressed("item_1")
   if game:get_item_assigned(1) == "iron_boots" then
      if hero:get_state() == "swimming" then
         hero:set_walking_speed(44)
         local x, y, layer = hero:get_position()
         hero:set_position(x, y, 0)
         game:set_value("iron_boots", true)
      else if game:get_value("iron_boots") == true then
         hero:set_walking_speed(88)
         local x2, y2, layer2 = hero:get_position()
         hero:set_position(x2, y2, 1)
         game:set_value("iron_boots", false)
    else
      sol.audio.play_sound("error")
end


And hopefully it's gonna work, lol.
#27
I'm trying to develop a system for the Iron Boots item (like in Ocarina of Time) and I'm able to get it working with sensors because items can't be used during swimming. Is the nullification of item use during swimming hardcoded in Solarus's engine or is there a way to set an item that it can only be used when swimming?
#28
I know this is laziness, but sometimes if there are a lot of maps in a folder and you want to see the script for a map, you have to go all the way to find the map then right click and open its lua. Maybe the map editor could have a button somewhere where you can simply click it and its lua will open. Maybe this button could be in between the Music tab and the tileset window?

Don't know if it would be too much work to do but I think that this could be very helpful for those projects with tons of maps.
#29
Okay, finally got it working. I think the problem was adding the map get game line.

Anyways, so it finally works except that the hero freezes when using the item and doesn't unfreeze. Not only that, but the animation doesn't change as I want it to. Here' what the book is trying to do:

function item:on_using()
  hero:set_animation(book)
  game:start_dialog("book.test")
  self:set_finished()
end

The book animation I'm referring to is an animation in the hero entity that I made which is just one frame in all four directions of him reading the book. But, nothing happens. Well, to be more precise, it freezes and nothing happens, lol.

This isn't what the book is going to do. I'm just testing to see if I can get this item to work per se. The purpose of the book is to check to see if the hero is in certain spots that require translating. When the location matches one of the books locations, then instead of getting the usual dialog, you'd get the translated dialog. In theory it should work. However, I want to give a message when the hero uses the book when there's nothing to read. I still want the animation to occur though because I want to first see if it works.[/code]
#30
Yeah, I probably should just give up trying to do everything from scratch (which is what I would like to do given a model/instructions or whatever and not just copy/pasting Mystery of Solarus's luas) for the moment. I know that it's more efficient to work off of the Solarus game and work my way from there, but I want to add way more items than Mystery of Solarus has. So by that reason alone I can't really use its menu. I did read over the code (all the luas to make the game run) and apparently there's like a million things I have to have going on in order to even make a Zelda game possible (before the player being even able to start a quest). I can design maps and dungeons and puzzles and items but in the end, all I can do is test. I can't really get a game started until I'm able to develop the system of equipping items.

That being said, I decided to try and code my item into Mystery of Solarus (and force equipping it) which actually works given what you suggested. So I really have no idea what's wrong with my own game. However, to move past my problem of something as simple as equipping the thing and try to at least make the item work before I can implement it in my own game, I'm trying to make the Book of Mudora. So I'll work off of Mystery of Solarus to at least test my items. I would like to be able to contribute as well in item scripting because my game is really ambitious and I'm working on a whole bunch of other things (I got an Iron Boots concept to work wonderfully and simply, so at least I'm happy for that, lol). As soon as I'm able to get my bearings in Solarus I can be able to share my discoveries with the community (like after I finish getting the Book of Mudora to work, lol).

Using this item requires a change in the hero's graphics (already created an animation and directions for it and set them up in the appropriate place in the hero tab) and named it 'book'. This is the code for the book:

local item = ...

function item:on_created()

  self:set_savegame_variable("possession_book")
  self:set_assignable(true)
end

function item:on_using()
sol.audio.play_sound("bush")
end


Ok, as I was getting the info you asked in order to help on the other game, now I can't get this to work in Mystery of Solarus either. Lemme first check again to see what I did wrong...

UPDATE:
Here's what I want the book to do:

local item = ...
local game = map:get_game()

function item:on_created()

  self:set_savegame_variable("possession_book")
  self:set_assignable(true)
end

function item:on_using()
  hero:freeze()
  hero:set_animation(book)
  game:start_dialog("book.test")
  hero:unfreeze()
end


The item is equipped as you say and everything works until I make the item do something. As long as the only thing in the book.lua is

local item = ...

function item:on_created()

  self:set_savegame_variable("possession_book")
  self:set_assignable(true)
end


it works. If I add the item:on_using() function to the book.lua, the error goes so far as to not even force equip it as you say. So basically, I can only force equip the item via the map script you gave me in the 1st slot so long as the book.lua has no other lines of code besides being created. The mystery continues...