ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
What is the proper syntax for this?

Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  11:57:44  15 October 2012
profilee-mailreply Message URLTo the Top
Daemonion
All About Audio
(Resident)

 

 
On forum: 09/27/2011
 

Message edited by:
Daemonion
10/15/2012 12:00:52
Messages: 567
What is the proper syntax for this?

I am making a main menu which changes the background texture/video based on which level is active in the current game.


if level and level.present() then
        local sg = CSavedGameWrapper(file:NameFull())		
        local level_name = sg:level_name()
	if level_name = ("l01_escape")
		xml:InitStatic("mm_l01_escape")
	end
        else
	        if level_name = ("l01_garbage")
		        xml:InitStatic("mm_l02_garbage")
                end
else
	xml:InitStatic("mm_start", self)
end	


Specifically, I think I am messing up with the level_name = ("l01_escape" . The stack trace when I CTD is blank.

This code, however, works just fine:

	if level and level.present() then
		local htime = level.get_time_hours()
		if htime <= 5 or htime >= 20 then
			-- night version
			xml:InitStatic("mm_night", self)		
		else
			-- day version
			xml:InitStatic("mm_day", self)
		end
	else
		xml:InitStatic("mm_start", self)
	end


With this last code, the game will check to see if a level/save has been loaded. If it has, it checks the time of that current game in progress and will display either a day or night version of the main menu when the ESC key is pressed. If a level has not even been loaded yet (ie when the game is first booted up), it will display a neutral (mm_start) main menu.

I want to do this same principle, but for each level. So, if the player is in Garbage, I want the main menu to show a specific background for Garbage.
  15:28:23  15 October 2012
profilee-mailreply Message URLTo the Top
Cromm Cruac
Сделано в Чернобыле
(Resident)

 

 
On forum: 11/19/2009
 

Message edited by:
Cromm Cruac
10/15/2012 15:32:19
Messages: 1143
Shouldn't that be

local level_name = level_name()

to get the current loaded level name

Also, the whole thing could be simpler:

if level and level.present() then
	xml:InitStatic("mm_"..level_name())
else
	xml:InitStatic("mm_start", self)
end

  19:52:12  15 October 2012
profilee-mailreply Message URLTo the Top
Daemonion
All About Audio
(Resident)

 

 
On forum: 09/27/2011
 

Message edited by:
Daemonion
10/15/2012 20:34:17
Messages: 567
With this code:

	local level_name = level_name()
	if level and level.present() then
		xml:InitStatic("mm_"..level_name())
	else
		xml:InitStatic("mm_start", self)
	end



I get this error:

Arguments     : LUA error: ...ow of chernobyl\gamedata\scripts\ui_main_menu.script:104: attempt to call global 'level_name' (a nil value)


Not sure where to go from here
  21:44:40  15 October 2012
profilee-mailreply Message URLTo the Top
Cromm Cruac
Сделано в Чернобыле
(Resident)

 

 
On forum: 11/19/2009
Messages: 1143
I've made a typo, sorry. It should be level.name not level_name


if level and level.present() then
	xml:InitStatic("mm_"..level.name())
else
	xml:InitStatic("mm_start", self)
end


The first line (local level_name = level_name()) is not necessary
  22:37:42  15 October 2012
profilee-mailreply Message URLTo the Top
Daemonion
All About Audio
(Resident)

 

 
On forum: 09/27/2011
 

Message edited by:
Daemonion
10/15/2012 22:38:07
Messages: 567

---QUOTATION---
I've made a typo, sorry. It should be level.name not level_name


if level and level.present() then
	xml:InitStatic("mm_"..level.name())
else
	xml:InitStatic("mm_start", self)
end


The first line (local level_name = level_name()) is not necessary
---END QUOTATION---


Hm, I am still getting an error (stack trace is blank). The game starts up properly, with the "mm_start" background, but crashes when going back to the menu after loading a save.

Here is the relevant code from my ui_main_menu.script http://pastebin.com/5LrkG7Us

Here is my ui_mm_main.xml http://pastebin.com/87m3chvL
  22:56:29  15 October 2012
profilee-mailreply Message URLTo the Top
Daemonion
All About Audio
(Resident)

 

 
On forum: 09/27/2011
Messages: 567
Also, I am correct in assuming that the level names are l01_escape, l02_garbage, etc etc, yes?
  23:16:17  15 October 2012
profilee-mailreply Message URLTo the Top
Cromm Cruac
Сделано в Чернобыле
(Resident)

 

 
On forum: 11/19/2009
Messages: 1143
It's probably missing ', self' where level.name() is. InitStatic requires 2 parameters.

xml:InitStatic("mm_"..level.name(), self)


And yes, level names are like that (same as the dir names in gamedata\levels)
  23:30:54  15 October 2012
profilee-mailreply Message URLTo the Top
Daemonion
All About Audio
(Resident)

 

 
On forum: 09/27/2011
Messages: 567

---QUOTATION---
It's probably missing ', self' where level.name() is. InitStatic requires 2 parameters.

xml:InitStatic("mm_"..level.name(), self)


And yes, level names are like that (same as the dir names in gamedata\levels)
---END QUOTATION---


That did it!

Thanks, Cromm!
 
Each word should be at least 3 characters long.
Search:    
Search conditions:    - spaces as AND    - spaces as OR   
 
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
 

All short dates are in Month-Day-Year format.


 

Copyright © 1995-2020 GSC Game World. All rights reserved.
This site is best viewed in Internet Explorer 4.xx and up and Javascript enabled. Webmaster.
Opera Software products are not supported.
If any problem concerning the site functioning under Opera Software appears apply
to Opera Software technical support service.