Popup Messages

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Popup Messages

Post by Fiodis »

I've been trying to get a popup message to show the first time the human player spawns, and not any of the other times. To this end, I wrote a code:

Code: Select all

	humanspawn = 1
	OnCharacterSpawn(
		function(character)
			if IsCharacterHuman(character) then
				if humanspawn =~ 1 then  -- This is line 50.  
				ShowPopup("level.ARI.beginningpopup")
				humanspawn = 2
				end,
			end,
		end
		)
And I stuck that inside ScriptPostLoad. I get a mungelog error:

Code: Select all

C:\BF2_ModTools\data_ARI\_BUILD\..\..\ToolsFL\Bin\luac.exe: ..\..\common\scripts\ARI\ARIc_con.lua:50: `then' expected near `='
ERROR[scriptmunge scripts\ARI\ARIc_con.lua]:Could not read input file.ERROR[scriptmunge scripts\ARI\ARIc_con.lua]:Could not read input file. [continuing]
   2 Errors    0 Warnings
The problem is that "then" is already there. It looks fine to me - I think I've got the punctuations in the right places and all - but I don't code LUA very often, and there's something I've obviously missed.

Also, a forum search told me that ShowObjectiveTextPopup() is better than ShowPopup(), but for this method, do you need ScriptCB_SetGameRules("campaign")?
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Popup Messages

Post by Maveritchell »

No commas.
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Popup Messages

Post by Fiodis »

A version without commas was one of the many others I tried. It comes up with the same error.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Popup Messages

Post by Maveritchell »

~= is correct
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Popup Messages

Post by Fiodis »

Ah, thanks. That gets rid of the mungelog errors, but the message still doesn't show in-game, and there's nothing related to it in the error log. Should I use == instead?
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Popup Messages

Post by Maveritchell »

Yes you should. Right now there is no way of filling the condition "humanspawn ~= 1".
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Popup Messages

Post by Frisbeetarian »

What's wrong with doing it the way the campaign scripts do it?
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Popup Messages

Post by Fiodis »

Well, they have it set up as objectives. I'm not sure if that matters or not, but I have a conquest map right now.

I also had tried several variations of popupText(), but it didn't work.

EDIT - Right, with == it didn't work either, but I got this:

Code: Select all

Message Severity: 2
.\Source\LuaCallbacks_Mission.cpp(2264)
ShowPopup() has been depricated. Please remove all references to it in code
I knew I'd get a debug error, but I thought that it would still work.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Popup Messages

Post by Frisbeetarian »

Code is code is code. It doesn't matter where it is. The most you have to worry about is including any ScriptCB_DoFile() calls that you need.

Code: Select all

onfirstspawn = OnCharacterSpawn(
	        function(character)
	            if character == 0 then
	            	ShowPopup("level.geo1.hints.hints")
	                ReleaseCharacterSpawn(onfirstspawn)
	                onfirstspawn = nil
	                BeginObjectivesTimer()
	                ScriptCB_EnableCommandPostVO(0)
	                BroadcastVoiceOver("GEO_obj_18", ATT)
	                ScriptCB_PlayInGameMusic("rep_geo_amb_obj1_3_explore")
	            end
	        end)
From the Geonosis script. You just want the popup part? OK, take the rest out. Why would your map being conquest matter?
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Popup Messages

Post by Fiodis »

I edited the Geonosis code slightly, so it looks like:

Code: Select all

            humanspawn = 0
	onfirstspawn = OnCharacterSpawn(
		function(character)
			if humanspawn == 0 then
				ShowPopup("level.ARI.beginningpopup")
				humanspawn = 1
               end
           end)
Same results; error log message and no popup. This code isn't much different from my own, it just doesn't have the IsCharacterHuman bit.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Popup Messages

Post by Frisbeetarian »

Your old code was closer. Your new code doesn't even reference the function input (the whole point of using OnCharacterSpawn()).

You just don't understand what the code I posted does. You would just need the following. It's like I said, just remove the part of the code you don't need. You don't need to add anything to it.

Code: Select all

onfirstspawn = OnCharacterSpawn(
           function(character)
               if character == 0 then
                  ShowPopup("level.ARI.beginningpopup")
                   ReleaseCharacterSpawn(onfirstspawn)
                   onfirstspawn = nil
               end
           end)
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Popup Messages

Post by Fiodis »

I tried that code, and still nothing shows up except for that error in the debug log. What does ReleaseCharacterSpawn do? And how does the line "if character = 0" work? Isn't "character" the variable of the character being spawned?
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Popup Messages

Post by Frisbeetarian »

Do a manual clean, remunge, and if the same error shows up, post the Lua script, it's probably somewhere else in the code.

I think that releasing an event clears it from memory, though I'm not completely sure. In single player, the human's character index is 0. Instead of checking to see if the character is human now, you just compare ir straight away.
kinetosimpetus
Imperial Systems Expert
Imperial Systems Expert
Posts: 2381
Joined: Wed Mar 25, 2009 4:15 pm
Projects :: A secret project
Games I'm Playing :: Warframe STO

Re: Popup Messages

Post by kinetosimpetus »

In one of the other scripting topics, the release event made it so it would only trigger once.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Popup Messages

Post by Frisbeetarian »

Nope, "onfirstspawn = nil" makes it so that the function does not exist and thus cannot be run again.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Popup Messages

Post by [RDH]Zerted »

Fiodis's new code is fine. The popup code is run once when the first time anyone spawn. It isn't the most efficient way to do it, but most people around here don't write efficient code.

SWBF2 passes in a value for character when it calls your callback function. That value is a character Id. Character ids are numbers, with 0 being assigned to the human player when in singleplayer. The if character == 0 then is saying only run this code when the player with the id of 0 spawns.

ReleaseCharacterSpawn 'turns off' the callback function. Your function will be called every time anyone spawns. To keep the popup from showing each time, you use the humanspawn variable. The other code doesn't have that check. Instead, it would show the popup each time the player with an id of 0 spawns. To prevent this from happening, the callback function is canceled/deleted/removed/released/turned off by using ReleaseCharacterSpawn. Use that function is slightly better as the game will no longer continue to call that callback function. (The game still will do other OnCharacterSpawn callback, but not the one that gets passed into ReleaseCharaterSpawn)

To get the popup to show, try setting the game to campaign mode. Its a function call, but I don't remember the exact name right now. Changing the mode may mess some other things up, but right now we're just trying to get the popup to work first.

Edit:
ReleaseCharacterSpawn(onfirstspawn) -- Tells the game to un-register that callback function
onfirstspawn = nil -- Just sets the variable to nil, just like any other =nil statement. This was done to clear up some Lua memory. We released the character spawn, so there is no reason to use that variable again. I don't believe onfirstspawn is a function. It holds the return value of OnCharacterSpawn(). I expect it to be some type of userdata IDing the registered callback. I've never looked into its type since there is really no point in exactly knowing it.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Popup Messages

Post by Frisbeetarian »

[RDH]Zerted wrote:To prevent this from happening, the callback function is canceled/deleted/removed/released/turned off by using ReleaseCharacterSpawn
I don't understand. If this is true, why do they set "onfirstspawn" to nil; it seems rather redundant.
[RDH]Zerted wrote:Fiodis's new code is fine.
I was saying that his code after his fourth post is better, because it checks to make sure the character is human. What Mav said should have solved the error, I just got confused because I thought he was saying the munge error was still showing up so I was checking with code I knew for sure worked.

Basically, I can't read.
Post Reply