Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing Code into a lang entry?
DanielRand47 Away
Member

Posts: 109
Threads: 16
Joined: Mar 2012
Reputation: 3
#1
Passing Code into a lang entry?

Hey guys. I'm looking at possibly having a situation where the player has to make it through a section where the lights are slowly being dimmed due to say a lack of power supply. You have 100% power and slowly drain 1% at intervals of 5 seconds. My question is, to know if there is a way to pass data from the hps file into the lang file which is written in XML.

HPS file code example
PHP Code: (Select All)
int Percentage 100//Class level variable
void OnStart()
{
  
AddTimer("Timer1"5.0f"DimLights");
}

void DimLights(string &in asTimer)
{
  
int PercentageLost 1;
  
Percentage Percentage PercentageLost;

//Some how pass Percentage into lang file.
  
SetMessage("Messages""PowerPercent"3.0f);
  
AddTimer(asTimer5.0f"DimLights");


LANG example
PHP Code: (Select All)
<CATEGORY Name "Messages">
        <
Entry Name "PowerPercent">"Percentage"%</Entry> <!--Percentage would be passed in from the hps file into the lang xml file.-->
</
CATEGORY

Does anyone know how to do this. Pass data from a script file into a XML file (LANG file)

Custom story is TRIAD. https://www.frictionalgames.com/forum/thread-35504.html
(This post was last modified: 02-16-2016, 03:02 AM by Romulator.)
02-16-2016, 12:50 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#2
RE: Please check the troubleshooting guides before posting!

Unfortunately, you cannot. You have to define the values in your lang file, then use code to call it.

<CATEGORY Name="Messages">
    <Entry Name="Percentage_100">100%</Entry>
    <Entry Name="Percentage_99">99%</Entry>
...
    <Entry Name="Percentage_1">1%</Entry>
</CATEGORY>

Using code, you'd have to call it in a timer that plays every 5 seconds and lowers your value. I've slightly adjusted my code to suit my knowledge of the engine, but it'll work in its simplest form, like this:

PHP Code: (Select All)
void OnStart()
{
    
SetLocalVarInt("PowerRemain"101); //Becomes 100 in first Timer step.
    
AddTimer(""5.0f"DimLights");
}

void DimLights(string &in asTimer)
{
    
AddLocalVarInt("PowerRemain", -1);
    if(
GetLocalVarInt("PowerRemain") == 0)
    {
        
//We have no power lol
    
}
    else
    {
        
SetMessage("Messages""Percentage_"+PowerRemain3.0f);
    }
    
AddTimer(""5.0f"DimLights");


The best way to make your entries for your lang, would best be if you have any experience in a computer language (C, Lua, Vb.NET) to get the computer to type out your entries using a loop. In something psuedocode-like, it may appear like this:

BEGIN
var <-- 100
do until var = 0
    print "<Entry Name=""Percentage_"""+var+">"+var+"%</Entry>"
    var <-- var - 1
loop
END

If you can't, I'll type one up later. I did all of this on my phone. https://dotnetfiddle.net/4sHWe5

Keep in mind, there are other methods! I believe FlawlessHappiness can help you by using numbered particle systems, but keep in mind that these likely won't always be on the screen.

Moving to the Development Support subforum. Please remember to keep all scripting and custom story related problems over there.
(This post was last modified: 02-16-2016, 03:24 AM by Romulator.)
02-16-2016, 02:51 AM
Find
DanielRand47 Away
Member

Posts: 109
Threads: 16
Joined: Mar 2012
Reputation: 3
#3
RE: Passing Code into a lang entry?

(02-16-2016, 02:51 AM)Romulator Wrote: Unfortunately, you cannot. You have to define the values in your lang file, then use code to call it.

<CATEGORY Name="Messages">
    <Entry Name="Percentage_100">100%</Entry>
    <Entry Name="Percentage_99">99%</Entry>
...
    <Entry Name="Percentage_1">1%</Entry>
</CATEGORY>

Using code, you'd have to call it in a timer that plays every 5 seconds and lowers your value. I've slightly adjusted my code to suit my knowledge of the engine, but it'll work in its simplest form, like this:

PHP Code: (Select All)
void OnStart()
{
    
SetLocalVarInt("PowerRemain"101); //Becomes 100 in first Timer step.
    
AddTimer(""5.0f"DimLights");
}

void DimLights(string &in asTimer)
{
    
AddLocalVarInt("PowerRemain", -1);
    if(
GetLocalVarInt("PowerRemain") == 0)
    {
        
//We have no power lol
    
}
    else
    {
        
SetMessage("Messages""Percentage_"+PowerRemain3.0f);
    }
    
AddTimer(""5.0f"DimLights");


The best way to make your entries for your lang, would best be if you have any experience in a computer language (C, Lua, Vb.NET) to get the computer to type out your entries using a loop. In something psuedocode-like, it may appear like this:

BEGIN
var <-- 100
do until var = 0
    print "<Entry Name=""Percentage_"""+var+">"+var+"%</Entry>"
    var <-- var - 1
loop
END

If you can't, I'll type one up later. I did all of this on my phone. https://dotnetfiddle.net/4sHWe5

Keep in mind, there are other methods! I believe FlawlessHappiness can help you by using numbered particle systems, but keep in mind that these likely won't always be on the screen.

Moving to the Development Support subforum. Please remember to keep all scripting and custom story related problems over there.

I figured I wouldn't be able to. I'll see what I can do. I'll also be more aware as to where threads such as this should go.
02-17-2016, 02:19 AM
Find




Users browsing this thread: 1 Guest(s)