Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

FPSC Classic Scripts / V109 Variable Tutorial

Author
Message
Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 22nd Apr 2008 08:45
Okay, guys, by request of Flatlander, I've compiled a short tutorial on the use of variables included with the V109 beta 3 release.


Now, to start off ... the title, of course:


Tutorial # Something: Variables


Yeah, I lost track of what tutorial number this is.


Anywho, let's get started!


To begin, I'll list the added conditions and actions that have to deal with variables:

Conditions:

VAREQUAL=X

- returns true if the current variable equals X

VARNOTEQUAL=X

- returns true if the current variable does not equal X

VARGREATER=X

- returns true if the current variable is greater than X

VARLESS=X

- returns true if the current variable is less than X


Actions:

GLOBALVAR=X

- set the current local variable index to wrire/read from to X

LOCALVAR=X

- set the current local variable index to wrire/read from to X

SETVAR=X

- set the value of the current variable to X

INCVAR=X

- increases the value of the current variable by X

DECVAR=X

- decreases the value of the current variable by X



Alright, that is verbatim from Lee's update for V109beta3.

Let us speculate a little about this. I have not used these variables, so let's not count on my own experience to get through this. Have no fear, though, we have Lee's examples to give us some insight!


Let us open the "pickuplockpicks.fpi" that was included with V109beta3:




Well, that looks pretty simple. The first line is a generic pickup sequence used in a lot of default scripts for picking stuff up.

The second line, however, is where we see some of our new commands:



According to our code, we move into this state once the player picks up the item.

Once we get here, we can see these two actions being used: globalvar and setvar.

What are they doing, though?

The GlobalVar action can be a bit confusing at first. What it does is tell FPSC which variable we are wanting to alter. In this case, we want to alter "Global Variable #1", which is why the script says "globalvar=1".

The SetVar action goes hand in hand with the previous action. Once FPSC knows which variable you are wanting to change, this commands does just that. It changes it. It will set the variable to the value in which you specify. So for the current circumstances, this action is setting "Global Variable #1" to a value of 1.


Great! Now, we know that once the player picks up the entity with this script attached to it, then the "Global Variable #1" will be equal to 1!



Moving on with our examples, we have "doorlockpick.fpi"

Let's take a look inside, shall we?




Whoa, that's a lot of code for a simple door!

But, this isn't just any door. It's a door that the player needs lock picks in order to open!

Now, remembering what we talked about with the other script will help us to decypher this one.

Here's a few rules to go by when reading the parts dealing about variables:

- The variable to be checked or altered is ALWAYS the one that was last set by either "globalvar" or "localvar"
- "Global Variable #1" is DIFFERENT than "Local Variable #1" (Pretty obvious)
- ALWAYS set the variable to be altered before trying to do anything with it. That includes checking it.


Okay, with that said, let's recall that in the other script, "Global Variable #1" will only be set to 1 if the player picked up some lock picks.

Now we can start to read this puppy from the top, starting with state 0.

- Set the variable to be used to "Global Variable #1"
- If the variable is set to 0 (Meaning we HAVEN'T picked up lock picks), then set "Local Variable #1" as the variable to be use, and set it to 1.

- Set the variable to be used to "Local Variable #1" as the variable to be used.
- If the player is close to the door and using the action key AND "Local Variable #1" is equal to 0, then set the variable to 1 and play a sound defined in the entity.
- If the player is close to the door and using the action key AND "Local Variable #1" is equal to 10, then increase the variable's value by 1 and play a sound defined in the entity.
- If the player is close to the door and using the action key AND "Local Variable #1" is equal to 20, then increase the variable's value by 1 and play a sound defined in the entity.
- If the player is close to the door and using the action key AND "Local Variable #1" is NOT equal to 0, then increase the variable's value by 1.
- If "Local Variable #1" is greater than 30, then go to state 1.

That sure does a lot.
Basically, while the user is within range and holds down the use key, they'll hear a couple sounds play while the variable is increasing in value until it gets to 30, then it'll go to state 1.

State 1, translated:

- Increase frames through animation 0
- If animation 0 is at the end, then turn the collision of the door off (So we can walk through it), set "Local Variable #1" to 20, and go to state 2.

That's pretty basic operation of opening the door.

States 2 & 3, translated:

State 2:
- Set the variable to be used to "Local Variable #1"
- If a 25 sided die is rolled and lands with 1 facing up and "Local Variable #1" is less than 21, then decrease "Local Variable #1" by 1.
- Go to state 3.

State 3:
- If "Local Variable #1" is not equal to 0, then go back to state 2.

- Set the variable to be used to "Local Variable #1"
- If the variable is equal to 0, then decrease frames through animation 0
- If animation 0 is back at the start, then set the frame to 0, turn collision back on (So we can't pass through the door), and go to state 0.


This is basically to close the door at a random point in time, and give the player enough time to get through.



Welp, that about does it for usage of variables.

What have we learned so far?

- How to set variables to be used.
- How to check variables.
- How to set and manipulate variables.
- To always set the variable to be used before trying to use it.



Have fun! And Good Luck!!!



The one and only,
~PlystirE~

Flatlander
FPSC Tool Maker
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 22nd Apr 2008 10:21
You have done very well and I thank you immensely. You have quite the ability to crank these tutorials out. Will get crackin' and try 'em out.
xplosys
18
Years of Service
User Offline
Joined: 5th Jan 2006
Playing: FPSC Multiplayer Games
Posted: 22nd Apr 2008 18:17
Much thanks. This is going to be killer, as the above script demonstrates.

Can you verify the number of available global and local variables?

Best.

Seth Black
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 22nd Feb 2005
Location: Pittsburgh, PA
Posted: 22nd Apr 2008 21:37
...greatly appreciated, Plystire.


Nomad Soul
Moderator
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location: United Kingdom
Posted: 22nd Apr 2008 23:15
Yeah thanks

You should probably watch this film called 'Grandma's Boy' when you get the chance.

You and Xplosys are like the character J.P.

Anyway thanks for sharing your encyclopedic knowledge of code
Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 23rd Apr 2008 03:53
You are most welcome, everyone!


@xplosys:

Sorry, I cannot say for sure how many variables you are allowed.

It might be a bad idea to just go grabbing random numbers, though.


@Nomad Soul:

I've seen that movie. Hilarious. Me and my friend laughed so hard at JP, mainly because.... well we occassioanlly did that robot thing to be funny before the movie even came out. Lmfao
(Okay, we never did the voice, but that was still a good touch, lol)


The one and only,
~PlystirE~

Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 23rd Apr 2008 03:56
On another note... I'm really surprised at the lack of, um... ... flexibility that these variables have.

You'd be VERY hard pressed to do anything like percentages or damage multipliers. Really anything that would require division or multiplication.


Also, I find it a pain-staking task of monitoring which variables are being used for what, especially if you get into having LOTS of stuff along the lines of Money, Fatigue, Stamina, STR, VIT, etc.

Doing an FPRPG with these would NOT be fun at all.


The one and only,
~PlystirE~

Flatlander
FPSC Tool Maker
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 23rd Apr 2008 04:47
Yea, you are probably right. It won't be easy and for a novice programmer it will be even more difficult. It looks difficult for me and I'm not a novice programmer.

I have tried your mod Plystrie but I get that little logo when I run the test on the bottom right saying something like Plystire's Mod. Can't remember. I hadn't tried building the actual game so don't know if this will be there on the game as well. I guess that is what has kept me from going with it.

BTW, I can't believe I didn't see the new fpi files giving an example of the variables (lockpick fpi's) and Lee even had mentioned them in the first post. anyway, they work fine for me and I can see some neat variations on that theme.
Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 23rd Apr 2008 05:36
Quote: "I run the test on the bottom right saying something like Plystire's Mod. Can't remember. I hadn't tried building the actual game so don't know if this will be there on the game as well."


Yes, that's been hard-coded into the engine to show up whenever the executable is run, that includes built games, too.

I tried to make it small enough so that gameplay wouldn't be hindered by it, but I suppose that would depend on your resolution.

If you're trying to make a commercial game (or just a game in general) and wanted it released without the watermark, you can email me about it, but right now I'm charging to have it removed. A jobless man has gotta eat, too, right? lol


The one and only,
~PlystirE~

Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 23rd Apr 2008 05:49
Here's a slightly optimized version of "doorlockpick.fpi"

By removing a bunch of the "localvar=" commands and reloacting it to a single one near the top, it should save a little bit of processing power when it runs the script





The one and only,
~PlystirE~

Flatlander
FPSC Tool Maker
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 23rd Apr 2008 06:15 Edited at: 23rd Apr 2008 06:22
Quote: "I'm charging to have it removed. A jobless man has gotta eat, too, right?"
lol

That's cool, didn't know we could do that and I don't mind paying for something that is worthwhile. I'd rather have it removed and just give you some top billing in the edits, even for my free games. That's just me.

I think what I will try to do is create a whole other folder for FPSC for your mod so I don't have to go back and forth. That way I can test the mod and still have all the original stuff in the main default folder. At least I think I can do this, unless the first install did something in the registry. Maybe instead of doing an install, I'll just move all the folders over to another folder. I have enough HD space.

Now I have to find your mod thread since I didn't bookmark it.

Addendum:

OK I found your new thread (I was searching for plystire) and I see all of that was answered in that thread. I can't think so abstractly as it would have Ply's mod in the name.
Flatlander
FPSC Tool Maker
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 23rd Apr 2008 17:06 Edited at: 23rd Apr 2008 17:09
@plystire
Quote: "you can email me"


I notice you don't have an email button (neither do I) and I would like to purchase your mod with no watermark.

Please send me an email to terrycox@mylastoutpost.com so we can make arrangements for this.

NOTE: Just thought about checking your thread for your email address. Oh, well I can't delete this so it will have to stand.
Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 24th Apr 2008 00:34
Email sent.

You can email me at the same email for my MSN Address.


The one and only,
~PlystirE~

Toasty Fresh
16
Years of Service
User Offline
Joined: 10th Jun 2007
Location: In my office, making poly-eating models.
Posted: 24th Apr 2008 10:10
So, can you have weapons that you have to buy with money in this? I'm guessing no...

Flatlander
FPSC Tool Maker
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 24th Apr 2008 10:27
Toasty, you can accumulate and spend money on things. Just can't have huds keeping track of the amount in real time (like Ply's mod can). You would have to come up with "next best thing" incredibly ingenious scheme for letting the player know where he's at with his money.

@Plystire, I didn't think about even moving my mouse cursor over the MSN button because I don't have MSN. I see it now.
Toasty Fresh
16
Years of Service
User Offline
Joined: 10th Jun 2007
Location: In my office, making poly-eating models.
Posted: 24th Apr 2008 15:04
Quote: "Just can't have huds keeping track of the amount in real time (like Ply's mod can)."


Wow, that sucks.

xplosys
18
Years of Service
User Offline
Joined: 5th Jan 2006
Playing: FPSC Multiplayer Games
Posted: 24th Apr 2008 16:20
Quote: "Just can't have huds keeping track of the amount in real time (like Ply's mod can)."


I don't see why not. It's just a matter of creating HUDS for the amounts and displaying them when money= it. Granted, you will want to make your increments 10, or at least 5, to keep from making so many, but you can do it. It may be best to create a keystroke to get the display. In fact, if it were done properly, you could display multiple variables in a HUD/Console like display.
I think I might work on that.

Best.

Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 24th Apr 2008 23:00
@xplosys:

I think it'd be best to do the HUD in a digit format. (Similar to the clock I made for coffee grunt in my Mod's thread)

However, like I said before, these variables lack a LOT of flexibility.


The one and only,
~PlystirE~

Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 24th Apr 2008 23:39 Edited at: 25th Apr 2008 00:12
Quote: "Just can't have huds keeping track of the amount in real time (like Ply's mod can). You would have to come up with "next best thing" incredibly ingenious scheme for letting the player know where he's at with his money."

Is it genius or elementary.

You only need 10 images for the numbers 0-9
Then you need 10 huds for each digit and stack them.
Setting each digit is easy really, now that we have a few variables.
You start at the far left digit and subtract the amount that matches leaving your remainder to be tested next.
Each digit has its own state that performs it display, inc/decrement, and then moves to the next digit.

I have not backed up my files yet for the v109 beta, but I will tonight so that I can make an example display for what I'm saying.
It's easier when you can see it, rather than having to visualize it, but it's not that hard really.


We want the cash (globalvar1) to stay the same while we perform our display test, but we need a counter for it (globalvar2)
We can edit the counter variable each time we cycle through the test which could be called after any change in globalvar1's value by another script. (store)

Here's is a explination if basic terms once we have set globalvar2 to the same value as globalvar1...
( NOTE: the example would only work for total less than 1000, but you could add many more digits if you wanted )



One image serves multiple digits..
Huds 900, 90, and 9 all use the 9 image.
It is the location in the display of the hud that makes the 9 a 90 or 900.

Quote: "However, like I said before, these variables lack a LOT of flexibility. "

Yeah sorta, but we are a lot more flexible now that we have them.

Don't forget to visit Conjured Entertainment

Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 25th Apr 2008 00:51
Quote: "Yeah sorta, but we are a lot more flexible now that we have them."


Your pseudocode just became a processing hinderance on FPSC, lol.

I wonder what's easier and more sound for a developer? The way we would have to do it using either your method or by having different variables per digit (my method), or this, using my Mod:







The ease of creating a simple effect should be taken into account here, IMHO. The less amount of time you spend making one thing, the more amount of time you can have to concentrate on actually doing something with it.


The one and only,
~PlystirE~

Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 25th Apr 2008 01:02 Edited at: 25th Apr 2008 01:11
Quote: "The ease of creating a simple effect should be taken into account here, IMHO. The less amount of time you spend making one thing, the more amount of time you can have to concentrate on actually doing something with it."

Yeah well, it's only simple your way because you are using your modded engine, and modding the engine is not that easy.

I don't think it will take that long to script a display for a cash counter with v109.

What we need to do for the global variables is use a numerical hud display like the lives, health, and ammo have.
I just did a backup, so I'm off now to get v109 and try these out.

Edit
Did anyone else notice the NEWJUMPHEIGHT=X action that is in v109?
Now we can buy special shoes that make us jump higher.
That should be fun.

Don't forget to visit Conjured Entertainment

Flatlander
FPSC Tool Maker
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 25th Apr 2008 01:16 Edited at: 25th Apr 2008 01:31
Yes, I know all of that CE. I did not say it couldn't be done. Only that there would be a more complex way of doing it; just as the pick up 5 items to open a door had to be complex in using only state, activated and ifused variables. In that situation, if you had seen my post regarding it, the variables have made it much easier.

And of course, it is now possible to at least have money or do other things with variables. It's just that it's not flexible and I'm not complaining about that. Just being realistic. Especially for those who are 12 years old. Do you think they would be able to do something that complex. Someone like yourself, Ply, or myself would surely have to do it for them.

This really shouldn't have to be a debate. Just being realistic; but, I do appreciate your giving an example of what needs to be done. Also, be aware that there is a bug in beta 3 that can be very annoying when testing a level. This bug will cause it to crash when reloading from the testlevel files (DBO/DBU universe files). Before retesting a level you need to force a rebuild of the level rather than it using the testlevel files. So, either delete the testlevel files before the next test run or add a single 1x1 room to the map. Lee said this will be fixed in beta 4. He's spending a lot of time trying to speed loading time up and is somewhat frustrated with it. We may not be able to see much decrease in loading time, but for me that's no problem.

CE -
Quote: "but it's not that hard really."


Maybe not for you or me but for perhaps the great majority as they purchased FPSC because they are not programmers.
Flatlander
FPSC Tool Maker
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 25th Apr 2008 01:25 Edited at: 25th Apr 2008 01:30
CE I have already tested NEWJUMPHEIGHT and posted on it and it is awesome. I set it to 500 and I went up so high it made me dizzy when I looked down. I set it to 100 and was able to jump on a light post I was using to test the LIGHTINTESITY actions.

Quote: "Yeah well, it's only simple your way because you are using your modded engine, and modding the engine is not that easy."


Life is made up of decisions and one of them is that if a person wants to use Ply's mod they can; but, they don't have to either. I have not yet decided but am getting close to making a decision. I don't know how much is going to be in v2 of FPSC but I do wish Ply and Lee could get together and Lee pay Ply for his work. That way Lee could spend less time on the finalization of it and get back to DBPro and X10.
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 25th Apr 2008 05:59 Edited at: 25th Apr 2008 06:03
Quote: "This really shouldn't have to be a debate."

It's not a debate.
I was just trying to offer a different perspective.

Quote: " It's just that it's not flexible and I'm not complaining about that. Just being realistic. Especially for those who are 12 years old. Do you think they would be able to do something that complex. Someone like yourself, Ply, or myself would surely have to do it for them. "

Yeah, but they are trying to learn to be programmers or they wouldn't be scripting.
I do plan on doing some scripts for the forums using these new conditions and actions, and I hope they help the 12 year olds.
The best way for them to learn is to study the scripts already written.
They need to learn how to work around obsticles, because they will run into plenty when programming.

I am just thrilled that Lee gave us some variables, and I know he will make these features better with new updates.
I would rather have this system so we can play around with this stuff, than waiting around for the complete full featured version.
The reason is simple, before you can get one improvement finished you have ideas for more.
We would be waiting forever if we wanted Lee to finish all of his plans for FPSC before he releases them.
This product is evolving and I think it will continue to evolve for quite some time.
All new features are limited because they are usually basic versions that will be improved upon.
So worrying about the limitations of using these variables is silly, because we have only just begun.

Quote: "Also, be aware that there is a bug in beta 3 that can be very annoying when testing a level. This bug will cause it to crash when reloading from the testlevel files (DBO/DBU universe files). Before retesting a level you need to force a rebuild of the level rather than it using the testlevel files. "

Thanks for the heads up on that one.


Quote: "CE I have already tested NEWJUMPHEIGHT and posted on it and it is awesome. "

Cool
I guess that super jump with the 'nanosuit' is not that special now after all.
Watch out CryTek!

I want the PLRFREEZE in beta 4 but I don't want the beta 4 bugs, so I'll wait for beta 5 I guess.
Until then, it variable experimentation time.

Don't forget to visit Conjured Entertainment

Toasty Fresh
16
Years of Service
User Offline
Joined: 10th Jun 2007
Location: In my office, making poly-eating models.
Posted: 25th Apr 2008 06:14
Can someone explain to me how you would make a shop script? I'm just starting to learn scripting, but I still know next to nothing.

Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 25th Apr 2008 06:33
@ The Toasty
I will be making one and posting it here in the forums when I am done.
I'm sure other people will make their own versions too, so there will be more than one to study.


@Flatlander
That Beta3 bug is a pain in the butt.
Thanks again for telling me, because that would have driven me crazy.

Don't forget to visit Conjured Entertainment

Flatlander
FPSC Tool Maker
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 25th Apr 2008 06:45 Edited at: 25th Apr 2008 06:49
CE, I'm definitely looking forward to your script because I consider you an expert FPSC scripter. I will be figuring something out as well. Sometimes its good to get more than one perspective, although, FPSC scripting is pretty unflexible in its event/action structure and therefore script often looks almost the same.

Yea, tell me about it. It's fixed in B4 and since I'm not worried about doing any actual development I will be using it so I don't get the dreaded crash. Lee's right about the texture issue. The melee m9 gloved fists are a transparent green.
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 25th Apr 2008 07:28 Edited at: 25th Apr 2008 07:30
Quote: "FPSC scripting is pretty unflexible in its event/action structure and therefore script often looks almost the same."

I was confused with the FPI when I started using it, but it grew on me.
Once it did click, I could see the genius behind its straight forward condition/action approach.
Yeah, it has its limitations, but every update expands it more and more with new actions and conditions.
I still have yet to use the SETTARGETNAME=X, even though I had plans for it before it was available.
I am going to definitly use it with the new PLRFREEZE=X, because those two will work magic together.

Quote: "CE, I'm definitely looking forward to your script because I consider you an expert FPSC scripter."

Thanks
I look forward to seeing everyone elses scripts too.

Don't forget to visit Conjured Entertainment

Nickydude
Retired Moderator
17
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Look outside...
Posted: 28th Apr 2008 02:16
Added you tutorial Ply (by the way, it's tutorial no #6 )

Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 28th Apr 2008 04:05
Lol, thanks Nickydude.

Hope it helps more people out.

I like having my tuts in your guide, because I know moe people will get tosee them that way.


The one and only,
~PlystirE~

Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 1st May 2008 07:07 Edited at: 1st May 2008 07:27
Quote: "Your pseudocode just became a processing hinderance on FPSC, lol."

Yeah but it is working FPSC scripts now.

Check out my video in the Store Scripts Thread.

Don't forget to visit Conjured Entertainment

Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 1st May 2008 11:53
Quote: "Yeah well, it's only simple your way because you are using your modded engine, and modding the engine is not that easy."


The modded engine is available to everyone.

And actually, it was very easy to put this variable system into the engine. I think I spent a total of 2 hours putting it in.


The video was nice, and congrats on getting the HUD to display properly!


The one and only,


Login to post a reply

Server time is: 2024-04-27 00:00:52
Your offset time is: 2024-04-27 00:00:52