Accessing Level Filename (not Level Title) on World Map

Description: Archive discussion
============================
Original description:
Official subforum for LunaLua - an extension framework for SMBX Engine Version 1.3 (which a core of SMBX 2.0). Share your creations that require the use of LunaLUA. You may also share info/tutorials on how to use LunaLUA.

Sambo M
Topic author, Count
Count
Avatar
Sambo M
Topic author, Count
Count
Age: 25
Reputation: 15
Posts: 264
Joined: 27 Jun 2014

Post #1by Sambo » 11 Sep 2015, 23:14

I need to be able to access the level's filename, but there's not a world.levelFilename value, and I can't locate the memory address for it.

I need to do something like this:

Code: Select all

function onLoop()
   level_code == string.match(world.levelFileName, "%D+%d+")
end
Image
Current Project:
Image

Kevsoft M
Angry developer
Angry developer
Avatar
Kevsoft M
Angry developer
Angry developer
Age: 24
Reputation: 93
Posts: 379
Joined: 26 Apr 2014
Location: Austria
Website

Post #2by Kevsoft » 12 Sep 2015, 10:19

Well there is the "Level"-Class (only for the overworld), which hasn't been documented yet but is already free to use:
https://github.com/Wohlhabend-Networks/LunaDLL/blob/master/LunaDll/LuaMain/LunaLuaMain.cpp#L667
So you could do:

Code: Select all

function onLoop()
  local firstLevel = Level.getByFilename("myFirstLevel.lvl")
  -- ...
  local currentFilename = ""
  local theLevelToCompare = Level.getByFilename(theFileNameVariable)
  if(theLevelToCompare)then
    if(theLevelToCompare == firstLevel)then -- This luna-object comparing has been implemented in the latest luna version.
      currentFilename = "myFirstLevel.lvl"
    end
  end
end

I know this is currently more a hack than a good way. I will implement more for the level object, if I find more time in the next couple weeks. (School has started again :/)
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.start() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.end() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬

Sambo M
Topic author, Count
Count
Avatar
Sambo M
Topic author, Count
Count
Age: 25
Reputation: 15
Posts: 264
Joined: 27 Jun 2014

Post #3by Sambo » 16 Sep 2015, 4:51

So, using this method I will have to do this:

Code: Select all

if(theLevelToCompare == firstLevel)then
  --do stuff
end

for each level?

This doesn't really save time for me. The idea is to use as little code as possible, so I can just grab the information from the level filename. Also, this seems complicated when I could just go through the level name:

Code: Select all

if(world.levelTitle) then
  if world.levelTitle == "Mushroom Road" then
    level_code = mi2
  elseif world.levelTitle == "South Castle Road" then
    --(repeat for every level)
  end
end

What I'm trying to do is run this, when the level name format is something like "mi2-Mushroom Road.lvl":

Code: Select all

function onLoop()
   level_code == string.match(world.levelFileName, "%D+%d+")
end

This would set level_code to mi2. Then I would get the data I needed using the level_code variable:

Code: Select all

if saveData:get(level_code .. "-dc-1") == 1 then
  --(load an indicator image showing that the Dragon Coin is collected)
end

But there's no rush for me to get this done. I'll just wait until you've implemented something like that. :)
Image
Current Project:
Image

Kevsoft M
Angry developer
Angry developer
Avatar
Kevsoft M
Angry developer
Angry developer
Age: 24
Reputation: 93
Posts: 379
Joined: 26 Apr 2014
Location: Austria
Website

Post #4by Kevsoft » 19 Sep 2015, 19:31

So with the new version you should now have access to the level filename.

But I did change some fields in the Level class:
"Level.levelTitle" --> "Level.title" and it is now of type string instead of a VBStr object.
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.start() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.end() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬

Sambo M
Topic author, Count
Count
Avatar
Sambo M
Topic author, Count
Count
Age: 25
Reputation: 15
Posts: 264
Joined: 27 Jun 2014

Post #5by Sambo » 21 Sep 2015, 1:25

Does that mean that this will work now:

Code: Select all

function onLoop()
   level_code = string.match(world.levelFileName, "%D+%d+")
end

Or do I need to do something else?
Image
Current Project:
Image

Kevsoft M
Angry developer
Angry developer
Avatar
Kevsoft M
Angry developer
Angry developer
Age: 24
Reputation: 93
Posts: 379
Joined: 26 Apr 2014
Location: Austria
Website

Post #6by Kevsoft » 21 Sep 2015, 21:11

Code: Select all

local levelTitle = world.levelTitle
if(levelTitle)then
  local levelObj = Level.getByName(levelTitle)
  if(levelObj)then
    local filename = levelObj.filename
  end
end

(would recommend to write an own function for this.
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.start() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.end() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬

Sambo M
Topic author, Count
Count
Avatar
Sambo M
Topic author, Count
Count
Age: 25
Reputation: 15
Posts: 264
Joined: 27 Jun 2014

Post #7by Sambo » 23 Sep 2015, 6:08

The code won't work. I probably just screwed it up when I made some changes:

Code: Select all

function getLevelCode()
   levelTitle = world.levelTitle
   if(levelTitle)then
      local levelObj = Level.getByName(levelTitle)
      if(levelObj)then
         local filename = levelObj.filename
      end
      level_code = string.match(filename, "%D+%d+")
   end
end

It returns this error:
thank you for your cooperation.PNG

I removed the "local" from "levelTitle" because it is used to check if the function needs to be run in onLoop. This keeps it from running on every loop.
Image
Current Project:
Image

Kevsoft M
Angry developer
Angry developer
Avatar
Kevsoft M
Angry developer
Angry developer
Age: 24
Reputation: 93
Posts: 379
Joined: 26 Apr 2014
Location: Austria
Website

Post #8by Kevsoft » 23 Sep 2015, 7:47

Nope, it was my fault:

Code: Select all

levelTitle = world.levelTitle

to

Code: Select all

levelTitle = world.levelTitle.str
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.start() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬
▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬ Signature.end() ▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬


Return to “LunaLua - Extension Framework”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest