Recent Posts

Pages: [1] 2 3 ... 10
1
Development / What does this error mean?
« Last post by lefthandedhero on Today at 02:39:32 AM »
Recently, I created a script specifically for code related to the hero, that I called hero_meta. Here is the code that's currently in this script:
Code: [Select]
local MAX_BUFFER_SIZE = 48
function hero:on_position_changed(x,y,z)
  local hero = self
  if not hero.position_buffer then hero.position_buffer = {} end
  local hero = self
  local dir = hero:get_sprite():get_direction()
  table.insert(hero.position_buffer, 1, {x=x, y=y, layer=z, direction=dir})

  if #hero.position_buffer > MAX_BUFFER_SIZE then
    table.remove(hero.position_buffer)
  end
end

The purpose of this code is to establish a maximum distance away from the hero and create a table storing the hero's prior movements within that distance.

When I try to run the quest, I keep getting this error:
Quote
Error: In main: scripts/meta/hero_meta.lua:2: attempt to index global 'hero' (a nil value)

What does this error mean? Any idea what is causing it to occur?
2
Development / Re: Need Help With Having an NPC Follow the Hero
« Last post by lefthandedhero on Today at 02:15:50 AM »
Not sure, but what i would guess is that the on_position_changed event gets triggered the next frame after you stopped moving, so maybe try to have one extra entry in the table and use two indices: one for the current hero step and one for the
NPC that is always 2 steps behind the hero -modulo will be your friend.
By the way, OH uses a standard .solarus zip file so you should be able to check the source code

Thank you.

I asked the developer of Ocean's Heart for the code they used for this, and they provided it, so I have replaced my code with it.
3
Development / Re: Need Help With Having an NPC Follow the Hero
« Last post by PhoenixII54 on May 29, 2023, 09:02:36 AM »
Not sure, but what i would guess is that the on_position_changed event gets triggered the next frame after you stopped moving, so maybe try to have one extra entry in the table and use two indices: one for the current hero step and one for the
NPC that is always 2 steps behind the hero -modulo will be your friend.
By the way, OH uses a standard .solarus zip file so you should be able to check the source code
4
Development / Re: Need Help With Having an NPC Follow the Hero
« Last post by lefthandedhero on May 21, 2023, 06:01:55 PM »
Using the suggestions above, I have refined the code. Here is the current version:
Code: [Select]
-- Follower's Movement 
  -- Initialize table to store the hero's old coordinates <List[0] = x, List[1] = y>:
  List = {}
  -- Obtain the hero's movement speed
  local speed = hero:get_walking_speed()
  -- Initialize the movement
  local movement = sol.movement.create("target")
  movement:set_target(Follower:get_position())
  movement:set_speed(speed)
  movement:start(Follower)
  -- Movement pathing:
  function hero:on_position_changed(x, y, layer)
  -- Update list and move accordingly
    -- If this is not the hero's first movement:
    if List[0] ~= nil then
      -- Move the NPC to the old coordinates
      movement:set_target(List[0], List[1])
    end
    -- Record the hero's current position:
    List[0] = x
    List[1] = y
  end

Initially, the movement works exactly as I would like. However, there are three problems that appear after the hero either stops moving or changes direction:

1. The NPC "Follower" continues moving after reaching the target position.
2. It is impossible for the hero to move backwards since Follower is in the way.
3. When I move the hero in a new direction, I want Follower to continue moving forward before then moving in the new direction, as I want Follower to follow the exact same path as the hero. Follower does not do this; I suspect this problem is related to problem 1.

Three questions:
1. How do I remove collision between the NPC Follower and the hero?
2. Any suggestions for how to make Follower stop moving when the hero stops moving?
3. Any idea what could be causing the third problem?

Incidentally, after playing Ocean's Heart recently, I reached a point in the game where an NPC follows the hero, and the NPC does exactly what I'm trying to get Follower to do: they follow the exact path the hero just walked. Does anyone know how Ocean's Heart did this?

UPDATE 2: I added the line, "Follower:set_traversable(true)", so now the hero can pass through Follower. The other two problems remain; Follower continues moving either left-and-right if facing up or down or up-and-down if facing left or right after the hero stops moving, and the movement only works the way that I want it to until the hero changes direction:

When I have the hero go in a new direction, Follower should move to the last place the hero was in the first direction before moving in the new direction, since I want Follower to follow the same path as the hero. Instead, Follower stands still for a while and then catches up. Any idea what is causing this?

There's another problem: despite Follower's speed being set to the hero's speed in the code, when I tested it, Follower slowly begins falling behind.

UPDATE 3: I set Follower to ignore obstacles to see if that was the reason it stood still whenever the hero turned to the left or right. It was the reason, and it revealed a different problem: despite the existence of the table being to record where the hero was previously, whenever the hero stops moving, follower stops at the hero's current position, not the hero's position a step previously.
5
Development / Re: Removing the select player screen
« Last post by PhoenixII54 on May 19, 2023, 06:40:47 PM »
Yes. In fact, the bare minimum required to start a game is : open main.lua, and in the solarus starting function, create a game object, setup starting point/HP/whatever you need at game start, and start the game. hints : sol.game.load; game:start() --> More info in the documentation page here. That's what file selection menus do, but in a more visual -and enhanced- way.
6
Development / Battle System
« Last post by Rhinosaur on May 19, 2023, 04:04:50 AM »
Hi Everyone,

I am new to Solarus and interested in trying to develop a game with it.  I was hoping to create a game with a battle system akin to something like Mario & Luigi: Superstar Saga.  Is this possible with Solarus?  Or would it be easier to develop using a different game engine?  If you are not familiar with Mario & Luigi Superstar Saga, it uses a turn based battle system which incorporates user input during the attacks.  So if you select a melee attack, you can get bonus damage by pressing the appropriate buttons at certain times.  Also, you can dodge the enemies attacks by jumping at the right time, etc.

My apologies if this has been answered already, I attempted to search but wasn't able to find the answer.

Thanks!
7
Development / Removing the select player screen
« Last post by xglichtrapx on May 11, 2023, 07:09:33 PM »
Hi all is there a way to remove the select player screen? For instance in the sample quest it goes straight from the title screen and directly to the start of the game.
8
Your projects / Ideas for a Zelda game?
« Last post by mine on May 10, 2023, 12:58:47 AM »
I'm a big Zelda fan, and I'm planning to use Solarus as an engine for a Zelda fan game...but I don't know what the plot should be, what the map should be like, what the dungeon themes should be, or anything! Please give me ideas!
9
Development / Re: Need Help With Having an NPC Follow the Hero
« Last post by lefthandedhero on May 09, 2023, 08:17:49 PM »
I don't see any obvious mistake (maybe i would have organized the list in the style 1 entry = an {x=x,y=y} pair but that's just a coding preference) so my guess is that your movement gets overwritten each frame you move and doesn't have time to even start until you stop moving.
So what you should try to do is to detect if the follower NPC already has a movement and update it's target (if possible) instead of recreating a new one each frame, and only create it again if it it reached its actual destination when the hero has stopped moving.

Thank you. That is most likely the reason for the first problem. I am currently working on modifying it as suggested.
10
Development / Re: Need Help With Having an NPC Follow the Hero
« Last post by PhoenixII54 on May 09, 2023, 11:40:17 AM »
I don't see any obvious mistake (maybe i would have organized the list in the style 1 entry = an {x=x,y=y} pair but that's just a coding preference) so my guess is that your movement gets overwritten each frame you move and doesn't have time to even start until you stop moving.
So what you should try to do is to detect if the follower NPC already has a movement and update it's target (if possible) instead of recreating a new one each frame, and only create it again if it it reached its actual destination when the hero has stopped moving.
Pages: [1] 2 3 ... 10