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 - llamazing

#181
Development / Pickable Item with No Shadow (Solved)
December 25, 2016, 12:02:10 AM
Using the ALTTP resource pack, I wanted to create a pickable treasure for the bottle, which looks bad if it has a shadow.

According to the Equipment Items documentation, the method item:set_shadow(shadow_animation), where shadow_animation is nil gives no shadow. However, when I try doing item:set_shadow(), I get the following error:

Error: In on_created: [string "items/bottle_1.lua"]:9: bad argument #1 to set_shadow (string expected, got no value))

I also tried item:set_shadow(false) and item:set_shadow("nil") to no avail. What am I doing wrong here?
#182
I know I was the one who suggested the change to the concave corner pieces (e.g. wall_low.corner_reverse.1-1), but I've come around full circle (see my original post here).

The reasons to keep it the way you had it is for compatibility with existing quests, as well as convenience since creating a simple corner with the piece now requires 5 tiles when it used to only need 3.

I also have a different suggestion on how the outcropping wall I used as an example in my original post can be created (and it would only take 4 tiles instead of the 5 it takes now). The good news is that it should only be a minor change to the tileset and would still preserve your existing layout.

See the first attached image for the changes I am now suggesting. The second image shows how a simple corner and an outcropping wall could be constructed with my proposed tile changes.
#183
Development / Re: Clear contents of Quest Editor console?
December 04, 2016, 08:01:33 PM
Quote from: Diarandor on December 04, 2016, 06:20:44 PM
There is already an open issue related to this:
https://github.com/solarus-games/solarus-quest-editor/issues/230
I agree that this feature is gonna be useful.

Ah, thanks for the info, Diarandor.
#184
Development / Clear contents of Quest Editor console?
December 04, 2016, 10:16:36 AM
Is there a way to clear what's displayed in the console of the Quest Editor? When there are a bunch of errors that I've fixed by editing my scripts, it would be nice to reset the console to a blank slate before running the quest again in order to verify the fix.

I checked the menus and right-click pop-up menu but didn't see anything to clear the contents of the console. I'm wondering if maybe there is a command that can be typed into the console to clear it?
#185
Development / Re: [Script Help] making a Rupoor
December 04, 2016, 10:13:02 AM
Assuming you're talking about the item:on_obtaining() function still, what you want is:
if variant==3 then
#186
Quote from: Diarandor on November 29, 2016, 02:02:28 AM
You should not create those surfaces in the on_draw event. On the one hand, you are creating them each time the event is called, which is probably unnecessary and may slow down the game. On the other hand, on_draw is not always called, so it might happen that your surface is not created and get an error or crash when you try to access it from other function.

Listen to what Diarandor is telling you. Just because version 1.5.1 mitigates the issue is no excuse to not fix the script. Re-creating all of your surfaces over and over again a hundred times per second is going to have unpredictable results.
#187
Development / Re: How do I print a string to txt file?
November 25, 2016, 06:03:22 AM
Quote from: zutokaza on November 25, 2016, 05:53:18 AM
Can I write the value of a variable?

You can write any string. How your script interprets the string is up to you.

The example you gave works, but if you are just writing simple integer values, you are probably better off saving the values to your savegame data like so:
Code (lua) Select

game:set_value("coordinate_x", 50)
game:set_value("coordinate_y", 40)


And to read it back:
Code (lua) Select

game:get_value("coordinate_x")
game:get_value("coordinate_y")
#188
Development / Re: How do I print a string to txt file?
November 25, 2016, 01:17:53 AM
If you want to write the somewhere relative to the quest directory, then you may want to use sol.file.open() instead of io.open(). By default it writes the file to the same location as your quest save data. This is probably what you'd want if you are writing supplemental data beyond what gets written to the save file.

If you are writing some sort of data log for debugging purposes, then you'd probably want to use io.open(), where you'd specify a full file path to somewhere on your local machine.

Also, be sure to read the documentation for io.open(), as you may want a write mode other than "w" depending on your usage.

Example:
Code (lua) Select

local file = sol.file.open("MyFile.txt", "w")
file:write("Hello World")
file:close()

#189
Development / Re: How can I overwrite the string?
November 12, 2016, 12:40:30 AM
Your code is a bit convoluted and difficult to follow, but I think your problem is that every draw cycle you are inserting characters into dl.split_string, but you never clear dl.split_string again. If I correctly understand what you are trying to do, you should add the following at line 111:
Code (lua) Select
dl.split_string = {}

A few additional comments...

1) Your endless if statements on lines to 131 to 387 could be optimized and simplified to a single line of code:
Code (lua) Select
text_img[ dl.split_string[char]:byte(1,1) ]:draw(screen, dl.place_x[char], dl.place_y[char])

You'd also have to change line 77 to:
Code (lua) Select
alphabet_split[abc:byte(1,1)] = abc

This would also mean that you'd have to rename your .png files where "a" is 97 and "A" is 65, etc.

Note that my example is not compatible with multi-byte utf-8 text, but it wouldn't be very hard to adapt it to be compatible (your script is not utf-8 compatible anyway).

2) hard-coding the sentence_word_length doesn't make sense. If you want to split the text into multiple lines, a better approach would be to use the new line character "\n" to designate the line breaks and then figure out where to split the lines dynamically at run time. For example:
Code (lua) Select
local text = "ZefK is gRaNd \nzefk is grand \nZEFK IS GRAND!"
for line in text:gmatch("[^\n]+") do print(line) end


3) You're doing a significant amount of processing every draw cycle, and I'm guessing you don't really need to recalculate the positions of every character 100 times per second. A better approach would be to create a surface that fills the screen, and then draw to that surface instead of all the times that you draw to your variable named screen. Then you could simply clear and redraw that surface any time the content of your text changes, and your on_draw() function would simply be:
Code (lua) Select
function sol.main:on_draw(screen) surface:draw(screen) end
#190
Quote from: MetalZelda on November 09, 2016, 01:11:52 AM
I was wondering, should the time be incremented in on_update or in on_draw

You want to use a timer instead. Have it update every in-game minute, and then as an added bonus it will pause automatically during dialogs if you set the context to the map.
#191
It would be easier to troubleshoot if the error given was "language not set" rather than "no such dialog".
#192
Development / Re: How do I do Mouse inputs?
October 24, 2016, 08:03:10 AM
Quote from: zutokaza on October 24, 2016, 06:59:02 AM
Doesn't sol.input.get_mouse_position() just return the position of the mouse?

You'd be using get_mouse_position() to find the current coordinates of the mouse cursor every time the timer loops, and in the on_draw() function draw your image you want to drag at those saved coordinates.

The code would look something like this (though you could clean it up to add an offset depending where on the source image the mouse clicked to line it up with the cursor better):

Code (lua) Select

local my_menu = {}

local mouse_update_timer
local timer_delay = 100 --time in ms

local drag_surface --dragged image to draw at cursor
local drag_x,drag_y --last known mouse coordinates

local function mouse_update() --called by timer while dragging
drag_x,drag_y = sol.input.get_mouse_position()
return true --return true makes the timer repeat until canceled
end

function my_menu:on_mouse_pressed(button, x, y)
if button=="left" then
local obj_x,obj_y,obj_width,obj_height = source_obj:get_bounds()

--mouse pressed within source object
if x>=obj_x and x<obj_x+obj_width and y>=obj_y and y<obj_y+obj_height then
print"begin drag at source"

drag_surface = source_obj
drag_x,drag_y = x,y

--stop timer if running
if mouse_update_timer then
mouse_update_timer:stop()
mouse_update_timer = nil
end

--start new timer (endless loop every 100ms until mouse released)
mouse_update_timer = sol.timer.start(my_menu, timer_delay, mouse_update)
end
end
end

function my_menu:on_mouse_released(button, x, y)
if button=="left" then
local obj_x,obj_y,obj_width,obj_height = dest_obj:get_bounds()

--mouse released within bounds of destination object
if x>=obj_x and x<obj_x+obj_width and y>=obj_y and y<obj_y+obj_height then
print"dragged to destination"
end

--don't draw source_obj at cursor anymore
drag_surface = nil
drag_x,drag_y = nil,nil

--stop timer if running
if mouse_update_timer then
mouse_update_timer:stop()
mouse_update_timer = nil
end
end
end

function my_menu:on_draw(dst_surface)

--code to draw rest of menu here...

--draws drag_surface at cursor
if drag_surface then drag_surface:draw(dst_surface, drag_x, drag_y) end
end


If it looks choppy, you can reduce the timer delay to update the mouse coordinates at a faster rate.
#193
Development / Re: How do I do Mouse inputs?
October 21, 2016, 11:50:34 PM
To do drag/drop, you can start a timer when the player clicks down on the object in the on_mouse_pressed(button,x,y) event. Then the timer calls sol.input.get_mouse_position() repeatedly while it is running and each time draws the object at the current location of the cursor. Having the timer update at a rate of 10 times per second would probably be good enough.

Finally, when the on_mouse_released(button,x,y) event is detected the timer would be stopped, and then you could perform some action depending on the current location of the mouse (where the player dragged the object to).
#194
On line 39, why do you create the empty function? Isn't that wasteful? Couldn't you just do the following instead? Lines 39 and 41 are modified.

Code (lua) Select

local function register_event(object, event_name, callback)

  local previous_callbacks = object[event_name]
  object[event_name] = function(...)
    return previous_callbacks and previous_callbacks(...) or callback(...)
  end
end
#195
Your projects / Re: Char input sneak peek
October 21, 2016, 08:15:00 AM
I haven't seen your script, but you should avoid using string.reverse() for text displayed on-screen because it is not compatible with multi-byte utf-8 strings (used in non-english text). If you really need to reverse a string, I guess you could write a custom reverse function that is utf-8 friendly.