Author Topic: Associating Variables With A Ship  (Read 6899 times)

0 Members and 1 Guest are viewing this topic.

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Associating Variables With A Ship
Okay. Here's another FRED question :)

In the mission I'm currently writing I want to have a variable that is associated with a certain ship. Basically at one point in a mission I need to be able to choose a ship from alpha wing and then based on which ship I've picked alter a variable.

In other words if Alpha 1 is choosen at random I need to set the variable to be 1. 2 if Alpha 2 was choosen and so on.

Anybody got an idea on how you can do this without having to have an event for each ship like this?

When
-Check somehow that Alpha 1 is the choosen ship
-Set Variable
-1

When
-Check somehow that Alpha 2 is the choosen ship
-Set Variable
-2

etc?
« Last Edit: March 04, 2005, 01:44:25 pm by 340 »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 
Associating Variables With A Ship
I'm no FREDder, but can't you do this the other way and have the ship be picked on basis of the variable? You can give a var a random value, right? If so, can you select Alpha X instead of Alpha 1?
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Associating Variables With A Ship
I don't think that one is any easier to be honest. In fact I think at best it's just the same set of problems in reverse. For my mission I think it would actually be harder.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Blaise Russel

  • Campaign King
  • 29
    • http://mysite.freeserve.com/sbre/index.html
Associating Variables With A Ship
I may not be understanding the question correctly, but what's stopping you from just changing the variable randomly 1 to 4? Why this middle stage of associating a random variable generation to a ship and then changing another variable on the basis of the ship chosen? Does something happen in-game that requires this method, or...?

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Associating Variables With A Ship
It's tricky to explain without giving away the entire mission. Everyone seems to like doing things the reverse way round so fair enough I'll explain things that way round.

 Suppose I did choose the variable at random.  I need to use this randomly selected variable to decicde which ship triggers a certain event. The variable will be used in a certain event later on.

Okay I've got the randomly selected variable. Lets say it's 3. How does that help me? The only way I can use the variable that I can think of is to have 4 events like this

when
- =
--Variable
--1
-Do something to alpha 1

when
- =
--Variable
--2
-Do something to alpha 2

etc.

What I'm wondering is if there is an easier way to do it. I want to know if there is a way to do it in one event because at the momnent I've got tonnes of places all over the mission where I'm having to use 4 events and it's just eating into my SEXP node count.

The best I've come up with so far (Which I thought up while posting this) was to create a subsystem. On alpha 1 I'd set it to 1. On alpha 2 I'd set it to 2. etc.

Then I could simply do this

when-arguement
any-of
Alpha 1
Alpha 2
Alpha 3
Alpha 4
-=
--Hits-left-subsystem
---Argument
---Counter Subsystem
--Variable
-Do-Whatever

Only problem is that for Alpha 1 the subsystem would appear on the HUD. It would also repair itself which means that after a few seconds the entire thing would stop working. It would also mean the appearance of a strange new subsystem on the ship.

So is there any way I can hide that? Do Bob's untagettable subsystems work yet? Can I get this subsytem to not auto-repair?

Failing all that is there anything else I could set to a number I could read in and out easily and which wouldn't get changed by the mission?
« Last Edit: March 04, 2005, 03:02:17 pm by 340 »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Sesquipedalian

  • Atankharz'ythi
  • 211
Associating Variables With A Ship
Use a string variable instead of a number variable.

Then set up the events somthing like this:
Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

The Scroll of Atankharzim | FS2 syntax highlighting

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Associating Variables With A Ship
I did try using string variables but abandoned the idea almost instantly because I couldn't test for them using = (At least FRED wouldn't let me. That might be a limitation of FRED rather than FS2_Open cause I do remember hearing that string variables were given various improvements soon after the source came out).

There might be another way of using them like you have there though so I think I should take another look at my mission and do some FRED testing. :)

EDIT : Just done a quick 2-3 minute test and only a few SEXPs I use that take a argument will change that to a string variable in FRED.

Did you do a lot of editing in notepad?
« Last Edit: March 06, 2005, 03:44:31 am by 340 »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Sesquipedalian

  • Atankharz'ythi
  • 211
Associating Variables With A Ship
No notepad editing whatsoever.  Do you mind showing the actual events you are using?
Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

The Scroll of Atankharzim | FS2 syntax highlighting

  

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Associating Variables With A Ship
Actually Goober suggested a way (on the MG internal) to get the mission to work using the subsystem trick I'd suggested so I'm going to try that.

In case you're wondering though my quick tests found that you couldn't substitute in a string variable in the target, Set-ship-position and sabotage-subsystem SEXPs (I basically went through my mission and substituted every reference to a ship I could find to see which ones worked so there are probably loads more that wouldn't work either).

Thanks for the idea though. I had thought of using a string variable in this way but I tested it with set-ship-position, found it didn't work and assumed that it was the whole idea of using a string that was flawed rather than just using it with that SEXP.

It is possible to build my mission using a string variable in this way if I used every-time argument to resolve the ship I'm using but that's pretty much the same as using a ships subsystem to do the same thing so I think I'll stick to that for the time being.

Thanks a bunch anyway :)
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Cobra

  • 212
  • Snake on a Cain
    • Skype
    • Steam
    • Twitter
Associating Variables With A Ship
This is very educational :D

Although what I would like to know is actually how they work and when to use them.
« Last Edit: March 09, 2005, 06:40:09 pm by 2299 »
To consider the Earth as the only populated world in infinite space is as absurd as to assert that in an entire field of millet, only one grain will grow. - Metrodorus of Chios
I wept. Mysterious forces beyond my ken had reached into my beautiful mission and energized its pilots with inhuman bomb-firing abilities. I could only imagine the GTVA warriors giving a mighty KIAAIIIIIII shout as they worked their triggers, their biceps bulging with sinew after years of Ivan Drago-esque steroid therapy and weight training. - General Battuta

 

Offline pyro-manic

  • Flambé
  • 210
Associating Variables With A Ship
They're covered in the FRED walkthrough. Go and do it again, and mess around with them to see what happens. :nod:

Basically they're used to store information, eg. if you wanted to keep track of how many ships got destroyed in a convoy, you could set up sexps to add 1 to a variable every time one died, and another event to check the value of the variable and give you a "mission failed" message or whatever.

(Note: This is only a simple example. Variables are a very useful tool that get used a lot in complex missions. As I said, the best way to understand them is to do the walkthrough. They cover the "Sleipner" transport wing's docking to the Orion IIRC...)
Any fool can pull a trigger...

 

Offline Cobra

  • 212
  • Snake on a Cain
    • Skype
    • Steam
    • Twitter
Associating Variables With A Ship
Quote
Originally posted by pyro-manic
They're covered in the FRED walkthrough. Go and do it again, and mess around with them to see what happens. :nod:

Basically they're used to store information, eg. if you wanted to keep track of how many ships got destroyed in a convoy, you could set up sexps to add 1 to a variable every time one died, and another event to check the value of the variable and give you a "mission failed" message or whatever.

(Note: This is only a simple example. Variables are a very useful tool that get used a lot in complex missions. As I said, the best way to understand them is to do the walkthrough. They cover the "Sleipner" transport wing's docking to the Orion IIRC...)


Got it in one. I've done half of the walkthrough mission, yet I still don't get variables...
To consider the Earth as the only populated world in infinite space is as absurd as to assert that in an entire field of millet, only one grain will grow. - Metrodorus of Chios
I wept. Mysterious forces beyond my ken had reached into my beautiful mission and energized its pilots with inhuman bomb-firing abilities. I could only imagine the GTVA warriors giving a mighty KIAAIIIIIII shout as they worked their triggers, their biceps bulging with sinew after years of Ivan Drago-esque steroid therapy and weight training. - General Battuta

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Associating Variables With A Ship
Variables?

The problem with variables is that it's hard to explain what you use them for. FRED's SEXPs are pretty powerful so variables tend to only be used when you come across a problem you can't solve any other way or which would be complicated to solve without them. That means that trying to come up with an example of how you use a variable means that you have to come up with a pretty detailed example.

The FRED2 Walkthrough has a good example of how to use a variable. In that mission you have 4 troop transports attempting to capture an orion. The transports will dock with the Orion. Spend a little while disgourging troops and then undock. If two of the troopships manage to successfully dock with the Orion then the orion is captured by the enemy forces. In the walkthrough they used variables as a way of achieving this. Basically they defined a variable called DockCount and added 1 to it every time one of the troop transports managed to successfully dock. When the value of the variable was 2 then the Orion could be captured and a simple when DockCount = 2 type event could be used to test this.

Although the walkthrough shows a good example of how to use a variable it's not the best example as though it would be a little tedious this example could have been made using normal SEXPs (basically a big OR checking that two transports made it)

So lets suggest something a little more complicated. Lets say that you want to say a certain number of soldiers are on the Orion. Let's say that it doesn't matter if the troop transport managed to get undocked safely since they are in battle armour. All that matters is the time the transports managed to stay docked to the Orion.

Now that is pretty much impossible without variables. With them. Well it's not easy but it's possible.

First you set up a variable called timedocked (with an inital value of 0). Then you set up a repeating event for each transport (Lots of repeats, repeat every second).

When
-and
--Has-Docked-Delay
---Transport x
---10 (lets say it takes 10 seconds after docking to open the airlock etc before troops start moving into the Orion)
--not
---has-undocked-delay
----Transport x
----0
-Modify-Variable
--TimeDocked
--- +
----TimeDocked
----1

Basically that event waits until the transport has been docked for 10 seconds and then adds 1 to the value of TimeDocked every second until the ship undocks.

Then you have an event like this

When
- =
--TimeDocked
--100
-do-whatever

That event triggers whenever timeDocked reaches 100 seconds regardless of whether each ship stayed docked for 25 seconds, one ship managed a full 100 seconds or any other combination you can think of. As you can see there is no way you could do that without variables :)

That's number variables. I've not used String variables because so far I've always wanted to use a SEXP with them that they don't like (For instance =. You can't test a String variable to see if it's equal to another string variable which basically rules them out for a lot of uses. Sesq may have a few good examples of their use.

If you're using FS2_Open you'll have access to persistant variables. These aren't reset at the end of a mission so they can be used in a campaign to do something like having something occur in Mission 12 based on a value from mission 4. (For instance have a cruiser take longer to appear depending on how badly shot up it was in the earlier mission). I've already written an example of how to use PV's here.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Associating Variables With A Ship
Quote
Originally posted by karajorma
Thanks for the idea though. I had thought of using a string variable in this way but I tested it with set-ship-position, found it didn't work and assumed that it was the whole idea of using a string that was flawed rather than just using it with that SEXP.
This sounds like a good feature to have, though.  It shouldn't be difficult to modify sexps to accept string variables in this way.  Remind me in a week and you'll have it. :)

As for your variable example, the best illustration I've seen is using variables for scanning the Sathanas subsystems or destroying its turrets.  Much simpler to increment a counter than to test for all possible combinations.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Associating Variables With A Ship
I agree but I wanted an example of something that couldn't be handled using the new When-Argument SEXPs and those could :)

That said a tutorial on how to use When-Argument is one of the things on my list for FAQ v2. Most people haven't realised how powerful and useful those SEXPs can be :)
Next person who asks how to use them may just get a really detailed example just like Cobra did for variables cause I'm trying to kill two birds with one stone whenever I answer technical questions at the moment :D

As for the use of string variables do you want a list of SEXPs that don't work with them? Cause at the moment I've found that the assigning a variable to a subsystem method has one major flaw I overlooked (I.e you can't test if a ship is dead because the ship is dead and the subsystem\variable is therefore unreachable! :D ). This isn't an unsurmountable problem but I'm having fun SEXPing at the moment and I want to see if I can make the mission with the mimimum number of missions.

BTW that reminds me. I think I asked before but IIRC When-argument internally expands into normal SEXPs right? Do the internal SEXP nodes count against the maximum number of SEXP nodes? I seem to remember you telling me they didn't but I had a mission hit the maximum number of SEXPs allowed with only around 15 events in it (3/4 of them were every-time-argument though).
« Last Edit: March 10, 2005, 01:57:21 pm by 340 »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Associating Variables With A Ship
Quote
Originally posted by karajorma
As for the use of string variables do you want a list of SEXPs that don't work with them?
No, I just need to be reminded.  (I'm on spring break ATM.)  All I have to do is add the capability for string variables to be treated as strings in the node.  It's really quite simple - less work even than when I changed sexps that only accepted hard-coded numbers to also accept numbers returned by other sexps.
Quote
BTW that reminds me. I think I asked before but IIRC When-argument internally expands into normal SEXPs right?  Do the internal SEXP nodes count against the maximum number of SEXP nodes? I seem to remember you telling me they didn't but I had a mission hit the maximum number of SEXPs allowed with only around 15 events in it (3/4 of them were every-time-argument though).
Yes, you did ask me before and I gave a detailed explanation which I don't feel like repeating. :p Suffice it to say that the game treats it like multiple expanded sexps but doesn't actually create new sexps.  So no extra nodes are used besides the ones you see.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Associating Variables With A Ship
Yeah. That's how I thought it worked. Odd that I run out of SEXPs with so few events. That said now that I think about it FRED did crash out about 10 minutes later so there might have been some other problem lurking.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Associating Variables With A Ship
Hmm.  The string variable thing was easier than I thought.  So much easier, in fact, that it was already implemented. :wtf: What problems were you having with it, exactly?

I did implement some string comparison functions (equals, greater than, and less than) though.  It was apparent that those were needed.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Associating Variables With A Ship
What I found was that it didn't work for some SEXPs so I just went back and tested it. I was assuming that it simply meant that certain SEXPs didn't work with a string variable. What I found was more interesting.

If you set up a variable like this ShipName(Alpha 1) All the SEXPs I tested worked.

The problem is that at the start of the mission I had a string variable which I didn't want to be assigned to any particular ship. So being a good programmer my variable looks like this  ShipName(Null). That doesn't work. You can only use a string variable in the SEXPs I tested (basically everything from the objectives sub menu) if the default value is a ship already present in the mission. You can't even assign it to Cancer 7 when there are two waves of cancer wing.

You can't assign it to be null in FRED. I have no idea what would happen if you assigned the variable to be null in the mission. Hopefully nothing cause I'm always going to be doing a null pointer check before using it. (So I shouldn't be doing anything stupid like assigning damage to null etc).

Anyway I don't know how fixable this is. If it's a five minute job then this is something I really want because the way my mission is currently set up I pretty sure I'm going to need variables set to null. If this is hard to do then just tell me and I'll see if I can reorganise the mission so that I don't need to do that. Now that I've got equivalence testing I suppose I could simply put in a ship very far away called Dummy and set the variable to that.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Associating Variables With A Ship
Quote
Originally posted by karajorma
The problem is that at the start of the mission I had a string variable which I didn't want to be assigned to any particular ship. So being a good programmer my variable looks like this  ShipName(Null). That doesn't work. You can only use a string variable in the SEXPs I tested (basically everything from the objectives sub menu) if the default value is a ship already present in the mission. You can't even assign it to Cancer 7 when there are two waves of cancer wing.
That's probably just FRED doing its error-checking.  Fire up Notepad and see what happens. ;)