Excellently done! Thank you very much. I'm new to coding, so what do you think went wrong with my loop?
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.
#16
Bugs & Feature requests / Re: Unknown Error: Testing for Ropes to activate chest
February 08, 2019, 11:00:32 PM #17
Bugs & Feature requests / [i]SOLVED: [Unknown Error: Testing for Ropes to activate chest][/i]
February 08, 2019, 03:47:38 AM
Hey everyone, back after tiling a good portion of an overworld, and the entirety of my first dungeon, when I ran into a problem while I was making my project. I was attempting to create a simple script which enabled a chest to appear when all of the Ropes in the room were killed, until I got to the point through trial and error where I'd created a script I couldn't possibly refine anymore, but nonetheless failed to generate the desired result. Instead, it played the sound which indicates the appearance of a chest once the room was loaded. Consider the attached script. What do you think went wrong? Did I refer to the wrong prefix in the has_entities command? I'm not sure. Any help would be appreciated
Post-Script: Hey, I'm not sure where I'd put this, I didn't see a sub-forum that was marked "Help", although I'm notorious for overlooking obvious things. If the mods would move this post to that potentially extant topic-section, I wouldn't be mad.
Post-Script: Hey, I'm not sure where I'd put this, I didn't see a sub-forum that was marked "Help", although I'm notorious for overlooking obvious things. If the mods would move this post to that potentially extant topic-section, I wouldn't be mad.
#18
Development / How allow the player to throw destructibles over lower walls?
January 16, 2019, 08:24:28 PM
I'm in the process of building my first dungeon, but in one room I presumed the player would be able to throw a pot across a gap to a switch. However, when I tested, I couldn't help but notice that the pot broke as soon as I threw it, as if the wall which represented the ledge was a wall in front of the hero's face. I tried a few things, but I couldn't figure out a way to get the pot over the ledge. Do y'all have any ideas?
#19
Bugs & Feature requests / Re: Having Trouble with Quest simulation
January 09, 2019, 06:33:59 AM
IT WORKED BOYS
Thanks much for all y'alls help
Thanks much for all y'alls help
#20
Bugs & Feature requests / Re: Having Trouble with Quest simulation
January 09, 2019, 12:46:54 AM
Come to think of it, I did originally make this quest in 1.5 before I knew that 1.6 was out. I then got 1.6 and it automatically updated the file. Do you think that the main.lua of that quest didn't change in that update, and is now incompatible with the current version?
#21
Bugs & Feature requests / Re: Having Trouble with Quest simulation
January 09, 2019, 12:11:20 AM
Here's the game manager script:
-- Script that creates a game ready to be played.
-- Usage:
-- local game_manager = require("scripts/game_manager")
-- local game = game_manager:create("savegame_file_name")
-- game:start()
local game_manager = {}
local initial_game = require("scripts/initial_game")
local multi_events = require("scripts/multi_events")
-- Creates a game ready to be played.
function game_manager:create(file_name)
local exists = sol.game.exists(file_name)
local game = sol.game.load(file_name)
if not exists then
-- Initialize a new savegame.
initial_game:initialize_new_savegame(game)
end
-- Function called when the player presses a key during the game.
game:register_event("on_key_pressed", function(game, key)
if game.customizing_command then
-- Don't treat this input normally, it will be recorded as a new command binding
-- by the commands menu.
return false
end
local handled = false
if game:is_pause_allowed() then -- Keys below are menus.
if key == game:get_value("keyboard_save") then
if not game:is_paused() and
not game:is_dialog_enabled() and
game:get_life() > 0 then
game:start_dialog("save_quit", function(answer)
if answer == 1 then
-- Continue.
sol.audio.play_sound("danger")
elseif answer == 2 then
-- Save and quit.
sol.audio.play_sound("danger")
game:save()
sol.main.reset()
else
-- Quit without saving.
sol.audio.play_sound("danger")
sol.main.reset()
end
end)
handled = true
end
end
end
return handled
end)
-- Function called when the player presses a joypad button during the game.
game:register_event("on_joypad_button_pressed", function(game, button)
if game.customizing_command then
-- Don't treat this input normally, it will be recorded as a new command binding.
return false
end
local handled = false
local joypad_action = "button " .. button
if game:is_pause_allowed() then -- Keys below are menus.
if joypad_action == game:get_value("joypad_save") then
if not game:is_paused() and
not game:is_dialog_enabled() and
game:get_life() > 0 then
game:start_dialog("save_quit", function(answer)
if answer == 2 then
-- Continue.
sol.audio.play_sound("danger")
elseif answer == 3 then
-- Save and quit.
sol.audio.play_sound("danger")
game:save()
sol.main.reset()
else
-- Quit without saving.
sol.audio.play_sound("danger")
sol.main.reset()
end
end)
handled = true
end
end
end
return handled
end)
return game
end
-- TODO the engine should have an event game:on_world_changed().
local game_meta = sol.main.get_metatable("game")
game_meta:register_event("on_map_changed", function(game)
local map = game:get_map()
local new_world = map:get_world()
local previous_world = game.previous_world
local world_changed = previous_world == nil or
new_world == nil or
new_world ~= previous_world
game.previous_world = new_world
if world_changed then
if game.notify_world_changed ~= nil then
game:notify_world_changed(previous_world, new_world)
end
end
end)
game_meta:register_event("on_game_over_started", function(game)
-- Reset the previous world info on game-over
-- so that notify_world_changed gets called.
game.previous_world = nil
end)
return game_manager
---------------------------------------------------------------------------------------
It's true that in main there's a string like the one you posted, but there's no such "start_game" string in game manager.
I'm currently running the default quest that's created when one goes to file>new quest
-- Script that creates a game ready to be played.
-- Usage:
-- local game_manager = require("scripts/game_manager")
-- local game = game_manager:create("savegame_file_name")
-- game:start()
local game_manager = {}
local initial_game = require("scripts/initial_game")
local multi_events = require("scripts/multi_events")
-- Creates a game ready to be played.
function game_manager:create(file_name)
local exists = sol.game.exists(file_name)
local game = sol.game.load(file_name)
if not exists then
-- Initialize a new savegame.
initial_game:initialize_new_savegame(game)
end
-- Function called when the player presses a key during the game.
game:register_event("on_key_pressed", function(game, key)
if game.customizing_command then
-- Don't treat this input normally, it will be recorded as a new command binding
-- by the commands menu.
return false
end
local handled = false
if game:is_pause_allowed() then -- Keys below are menus.
if key == game:get_value("keyboard_save") then
if not game:is_paused() and
not game:is_dialog_enabled() and
game:get_life() > 0 then
game:start_dialog("save_quit", function(answer)
if answer == 1 then
-- Continue.
sol.audio.play_sound("danger")
elseif answer == 2 then
-- Save and quit.
sol.audio.play_sound("danger")
game:save()
sol.main.reset()
else
-- Quit without saving.
sol.audio.play_sound("danger")
sol.main.reset()
end
end)
handled = true
end
end
end
return handled
end)
-- Function called when the player presses a joypad button during the game.
game:register_event("on_joypad_button_pressed", function(game, button)
if game.customizing_command then
-- Don't treat this input normally, it will be recorded as a new command binding.
return false
end
local handled = false
local joypad_action = "button " .. button
if game:is_pause_allowed() then -- Keys below are menus.
if joypad_action == game:get_value("joypad_save") then
if not game:is_paused() and
not game:is_dialog_enabled() and
game:get_life() > 0 then
game:start_dialog("save_quit", function(answer)
if answer == 2 then
-- Continue.
sol.audio.play_sound("danger")
elseif answer == 3 then
-- Save and quit.
sol.audio.play_sound("danger")
game:save()
sol.main.reset()
else
-- Quit without saving.
sol.audio.play_sound("danger")
sol.main.reset()
end
end)
handled = true
end
end
end
return handled
end)
return game
end
-- TODO the engine should have an event game:on_world_changed().
local game_meta = sol.main.get_metatable("game")
game_meta:register_event("on_map_changed", function(game)
local map = game:get_map()
local new_world = map:get_world()
local previous_world = game.previous_world
local world_changed = previous_world == nil or
new_world == nil or
new_world ~= previous_world
game.previous_world = new_world
if world_changed then
if game.notify_world_changed ~= nil then
game:notify_world_changed(previous_world, new_world)
end
end
end)
game_meta:register_event("on_game_over_started", function(game)
-- Reset the previous world info on game-over
-- so that notify_world_changed gets called.
game.previous_world = nil
end)
return game_manager
---------------------------------------------------------------------------------------
It's true that in main there's a string like the one you posted, but there's no such "start_game" string in game manager.
I'm currently running the default quest that's created when one goes to file>new quest
#22
Bugs & Feature requests / Re: Having Trouble with Quest simulation
January 08, 2019, 07:23:38 AM
While that's the case, where should I insert then game_manager:start_game()? What prefix should I use? Function, game, game_meta, or another? Thanks much for y'alls help by the way, been a great help so far
#23
Bugs & Feature requests / Re: Having Trouble with Quest simulation
January 06, 2019, 10:32:16 PM
So I inserted the line Alex recommended, and I booted. The results: I got the logo going now, but then I'm presented with the same black screen and a new error. This one reads:
>Error: In on_finished: main.lua:20: attempt to call method 'start_game' (a nil value)
The main.lua script does make mention at the beginning a similar require("scripts/game_manager) line, so that's not the problem this time. Here's copy of the script (problem line is italicized. I tried playing around with it the best I could but I didn't make any headway).
-- This is the main Lua script of your project.
-- You will probably make a title screen and then start a game.
-- See the Lua API! http://www.solarus-games.org/doc/latest
local game_manager = require("scripts/game_manager")
-- This function is called when Solarus starts.
function sol.main:on_started()
-- Setting a language is useful to display text and dialogs.
sol.language.set_language("en")
local solarus_logo = require("scripts/menus/solarus_logo")
-- Show the Solarus logo initially.
sol.menu.start(self, solarus_logo)
-- Start the game when the Solarus logo menu is finished.
solarus_logo.on_finished = function()
game_manager:start_game()
end
end
-- Event called when the player pressed a keyboard key.
function sol.main:on_key_pressed(key, modifiers)
local handled = false
if key == "f5" then
-- F5: change the video mode.
sol.video.switch_mode()
handled = true
elseif key == "f11" or
(key == "return" and (modifiers.alt or modifiers.control)) then
-- F11 or Ctrl + return or Alt + Return: switch fullscreen.
sol.video.set_fullscreen(not sol.video.is_fullscreen())
handled = true
elseif key == "f4" and modifiers.alt then
-- Alt + F4: stop the program.
sol.main.exit()
handled = true
elseif key == "escape" and sol.main.game == nil then
-- Escape in title screens: stop the program.
sol.main.exit()
handled = true
end
return handled
end
>Error: In on_finished: main.lua:20: attempt to call method 'start_game' (a nil value)
The main.lua script does make mention at the beginning a similar require("scripts/game_manager) line, so that's not the problem this time. Here's copy of the script (problem line is italicized. I tried playing around with it the best I could but I didn't make any headway).
-- This is the main Lua script of your project.
-- You will probably make a title screen and then start a game.
-- See the Lua API! http://www.solarus-games.org/doc/latest
local game_manager = require("scripts/game_manager")
-- This function is called when Solarus starts.
function sol.main:on_started()
-- Setting a language is useful to display text and dialogs.
sol.language.set_language("en")
local solarus_logo = require("scripts/menus/solarus_logo")
-- Show the Solarus logo initially.
sol.menu.start(self, solarus_logo)
-- Start the game when the Solarus logo menu is finished.
solarus_logo.on_finished = function()
game_manager:start_game()
end
end
-- Event called when the player pressed a keyboard key.
function sol.main:on_key_pressed(key, modifiers)
local handled = false
if key == "f5" then
-- F5: change the video mode.
sol.video.switch_mode()
handled = true
elseif key == "f11" or
(key == "return" and (modifiers.alt or modifiers.control)) then
-- F11 or Ctrl + return or Alt + Return: switch fullscreen.
sol.video.set_fullscreen(not sol.video.is_fullscreen())
handled = true
elseif key == "f4" and modifiers.alt then
-- Alt + F4: stop the program.
sol.main.exit()
handled = true
elseif key == "escape" and sol.main.game == nil then
-- Escape in title screens: stop the program.
sol.main.exit()
handled = true
end
return handled
end
#24
Bugs & Feature requests / Having Trouble with Quest simulation
January 06, 2019, 08:42:35 PM
I've been back on Solarus ever since I saw it got updated again, but unfortunately I've not been able to get the "Run quest" function of the quest editor to run. Whenever I click "run quest", the screen merely remains blank (without presenting the solarus logo) and eventually I get the following error:
>Error: In main: scripts/game_manager.lua:103: attempt to call method 'register_event' (a nil value)
Here's the problem line:
>game_meta:register_event("on_map_changed", function(game)
However, when I go and check that particular line and cross-reference it with another line (located above line 103) that contains the method "register_event", it seems to be working just fine. Doesn't that mean that register_event has a non-nil value? For example, here's a line that makes use of register_event that does not incur an error, located above the problem line
>game:register_event("on_joypad_button_pressed", function(game, button)
Now, I know that this has "game:" instead of "game_meta:" but I changed it to "game:" and it gave me an error at that line. I'm not sure that'd make a difference either. Anyways, I probably need someone technically competent to aid me here, go ahead and comment if you need more info.
>Error: In main: scripts/game_manager.lua:103: attempt to call method 'register_event' (a nil value)
Here's the problem line:
>game_meta:register_event("on_map_changed", function(game)
However, when I go and check that particular line and cross-reference it with another line (located above line 103) that contains the method "register_event", it seems to be working just fine. Doesn't that mean that register_event has a non-nil value? For example, here's a line that makes use of register_event that does not incur an error, located above the problem line
>game:register_event("on_joypad_button_pressed", function(game, button)
Now, I know that this has "game:" instead of "game_meta:" but I changed it to "game:" and it gave me an error at that line. I'm not sure that'd make a difference either. Anyways, I probably need someone technically competent to aid me here, go ahead and comment if you need more info.