Pausing?

Started by Zefk, August 31, 2016, 03:21:18 AM

Previous topic - Next topic
Quote from: Zefk on September 01, 2016, 11:09:12 AM
With:
Code ( lua) Select
  local foo = require("scripts/volume_control"); foo:f(game)


I get:
2140] Error: In on_finished: [string "scripts/volume_control.lua"]:125: attempt to index local 'game' (a string value)

Don't call your variable "foo", it was just an example.
Then you need to learn how to understand error messages. This one means that at line 125 of your volume_control.lua script, game is a value of type string. It should be a value of type game.

Also, I read your volume_control script and there are big problems. You define events game:on_paused(), game:on_unpaused(), sol.main:on_draw() and sol.main:on_key_pressed(). It means that you overwrite them if they already exist. The proper way would be to define game events in only one script (in my projects, I use the game_manager.lua script for that) and similarly the sol.main events in only one script (normally main.lua). Another solution is to allow multiple events on the same objects, which is now possible with the multi_events.lua script.


QuoteThen you need to learn how to understand error messages. This one means that at line 125 of your volume_control.lua script, game is a value of type string. It should be a value of type game.

I know what it meant. I was just showing the error message.

I think I will go with:
Code ( lua) Select
sol.main.load_file("scripts/volume_control.lua")(game)

In the long run I think it will be easier for me.

Others can modify it for require() if they want as I do not completely understand it and feel like it will make my simple script more complicated than it should be.

September 01, 2016, 11:53:45 AM #17 Last Edit: September 01, 2016, 11:59:35 AM by Christopho
A double function call, I don't find this easy to understand ;)

The worse thing is that scripts that work the standard way (for require) cannot be used with loadfile(), and vice-versa: scripts working with loadfile() cannot be used the standard way. In the sample quest and all tutorials, I always use require().

Please never use loadfile(), especially for scripts that load resources like images because they are executed again every time! It can become terribly slow in real situations like a pause menu.

September 01, 2016, 09:09:20 PM #18 Last Edit: September 01, 2016, 10:34:57 PM by Zefk
QuotePlease never use loadfile(), especially for scripts that load resources like images because they are executed again every time! It can become terribly slow in real situations like a pause menu.
I will take that in mind.  I am still getting used to Lua syntax. I will stalk your game scripts later.  ;D

I updated the main script, cleaned up comments, fixed 2 bugs, and credited everyone. Please let me know if any additional credit is wanted or changed related to the individual.

Updated script

The project and a complete tutorial will be here by Sunday for this script. You will be able to use the images and everything. It only took me 5 minutes to make the images and the images can be replaced with anything. They do not have to be dots because they could be bars.

Edit:
Noticed a bug when walking. I fixed.  No more bomb walking sounds.

P.S. I became a Sr. Member. That means I need to make some sound effects to celebrate the rank up.