Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

Do scripts not recognise minus numbers?


Mysterious Mr. Bear
 Share

Recommended Posts

Hi everyone, this has me stumped right now, wondered what you'd make of it all and wether you'd had the problem before. Here is a piece of my script. (some of this is a bit irrelivant but might help explain what it does, I put all the needed info in a paragraph at the bottom)

			Charter. FundsNET = (Charter. MaterialsOUT * 150) + (charter. FoodOUT *20) + (Charter. FundsPRO) + (Charter. FundsBONUS) - (Charter. MaterialsIN *250) - (charter. FoodIN *30) - (Charter. FundsDEMAND)

	If Charter. FundsNET < 0

		DEBUG.NOTIFICATION ("Net loss of funds detected'")

		If (charter. FundsNET) - (Charter. FundsNET * 2) > (Charter. Funds)

					DEBUG.NOTIFICATION ("Net loss is below current funds'")

			if (charter. MaterialsIN) + (Charter. FoodIN) > 0

				debug. Notification ("Your Funds are depleted- all imports halted.")

				charter. MaterialsIN = 0

				Charter. FoodIN = 0

			endif

			Charter. FundsNET = (Charter. MaterialsOUT * 150) + (charter. FoodOUT *20) + (Charter. FundsPRO) + (Charter. FundsBONUS) - (Charter. MaterialsIN *250) - (charter. FoodIN *30) - (Charter. FundsDEMAND)

			If (charter. FundsNET) - (Charter. FundsNET * 2) > (Charter. Funds)

				debug.Notification ("Your Funds are depleted- Moral is dropping.")

			endif

		endif

	endif

	debug.notification ("Chceked Funding Net gains. Changes made as required.")
This is an integeral part of script in my RTS style mod that runs before the daily transactions of materials, food and funds take place. It is designed to detect if the transactions that are about to happen would cost more than you have (FundsNET is how much your funds are depleted or increased each day, based on how many materials and food you are importing and exporting (MaterialsIN, MaterialsOUT etc) and how much money you are producing each day (FundsPRO and fundsBONUS). Whilst the calculation for working out the funds gain is (over) complicated, it deffinatly works as message boxes display the number to be -1000 in my testing enviroment (as MaterialsIN is set to 4, and everything else is set to 0).
			Charter. FundsNET = (Charter. MaterialsOUT * 150) + (charter. FoodOUT *20) + (Charter. FundsPRO) + (Charter. FundsBONUS) - (Charter. MaterialsIN *250) - (charter. FoodIN *30) - (Charter. FundsDEMAND)

	If Charter. FundsNET < 0

		DEBUG.NOTIFICATION ("Net loss of funds detected'")

This bit of script runs at the start of every day, but the message "net loss of funds detected" at the very begining of the script doesn't even display, which means this script is not detecting fundsNET to be below 0. How do I fix this, or work around this? It seems rediculous to not include a way to recognise minus numbers... am I using the wrong type of variable? they are all INT variables, do they need to be FLOATs or something?

Any help would be greaaatly appreciated!!!

Mysterious Mr. Bear :D :D

Link to comment
Share on other sites

First, try removing the space after your '.' reference symbol.

And put parethesis around your condition.

from:

If (charter. FundsNET) - (Charter. FundsNET * 2) > (Charter. Funds)

to:

If (charter.FundsNET - (Charter.FundsNET * 2)) > (Charter.Funds)

You may have to take the math OUT of the IF condition all together.

myVal = Charter.FundsNET * 2

If (charter.FundsNET - myVal) > (Charter.Funds)

Link to comment
Share on other sites

Wait just realised, thats not actually where the problem is coming from... :S

the problem starts with

If FundsNET < 0

It isn't recognising FundsNET as a negative number! it needs to do this before I can continue, as the script can only be allowed to run if it is a minus number. What do you think could be causing this? Just to recap:

FundsNET is DEFINITELY-1000, the message box displays this clearly.

There is a check to see if FundsNET is less than 0 to see if the script should run.

This check is failing and reporting that it is more than or equal to zero.

I'm going to try using float variables but since the message box worked I cant see it helping...

Link to comment
Share on other sites

I can see no way in which it is changed and apart from the check to see what day it is, it is not in another condition (other things run fine inside this condition as well). I will try giving fundsnet a -20 value right before the check, and see if this fixes things. The variable Fundsnet is from within another script- could this be effecting things?

Thanks Eaglemania, glad to know its not a flaw in the script language... Just got to figure out what is going wrong! I'll try copying and pasting that exact piece of script into mine and see if that works, just to test....

Link to comment
Share on other sites

Ok, I've been working on it, and I think I have got to the bottom of it completly by accident.

Firstly, I duplicated an object I made with a faulty script (this script holds the variables like FundsNET fundsIN etc). It was faulty because I had been working on it and not finished it when I got distracted by this- it works fine storing the variables but it can only be acitvated once, because the script only runs if the variable "Ready" is equal to zero and the script does not set this back to zero before finishing.I intended to turn this duplicate into a new object and attach a new script, so I could run "SV" console commands on it in-game and check the status of these pesky minus variables. But I forgot to do this, and so ended up with two identical objects with the same script.

When I activated these, I noticed that I could activate BOTH of these, and the menu would come up once for each one. This means that the "Ready" variable was not being stored globably- it was seperate to both of the objects. that means there were two differnt instances of the same variable.

...MY ENTIRE SCRIPT IS WORKING ON THE CHECKING OF THESE VARIABLES!!! If the script AAMBcCharterSCRIPT can exist twice with two competly differnt sets of variables, how can AAMBcCharterSCRIPT. FundsNET ever display the correct variable??

That was very badly explained but I hope you understand where I'm comming from... the reason FundsNET is not being read as below zero is because it is a variable in an object specific script, and is being called from outside of that script without any way to specify the object.

My plan of action is... well, I don't know. This complicates things because these variables need to be manipulated in at least four differnt places- from the players tent, from interaction with NPC workers, from interaction with a merchant NPC, and from random events.

New question: how do I ensure these variables are global? Turning them into.. well, global variables seems very complicated as the scripting changes completly and I get the impression this is not how they are desinged to work. Do quest scripts store variables perminantly, in a way that can be modified by other scripts? or is there a way to specify WHAT OBJECT to get the FundsNET variable from when I call AAMBcCharterSCRIPT. FundsNET? Any work around here would be appreciated.

Thankyou,

Mysterious Mr. Bear :D :D

Link to comment
Share on other sites

Globals are very easy to setup and use.

1. You create the global you want to use in the >Miscellaneous >Global listing.

LevelersMaxGoldGBL

2. You then define that global as a property to your script.

GlobalVariable Property LevelersMaxGoldGBL Auto

3. You can then get the value of that global like this:

int myGoldAmount = LevelersMaxGoldGBL.GetValue() as int

4. You can also set the value of the global like this:

LevelersMaxGoldGBL.SetValue(100)

And it can be used like this in any script.

Link to comment
Share on other sites

Aaaah right! So to use them in these scripts, I would have to first set all of my properties and variables to the global settings

FundsIN = FundsINGBL.GetValue() as int

FoundsOUT = FundsOUTGBL.Getvalue() as int

ect, ect

do all of my scripting

then at the end of the script,

FundsINGBL.setvalue(FundsIN)

FundsOUTGBL.setvalue(FundsOUT)

and then these can be used in multiple scripts through this method?

Link to comment
Share on other sites

Right, my new script works as follows.

I have declared all the global variables, as

GlobalVariable Property AAMBMaterialsGBL  Auto  

GlobalVariable Property AAMBMaterialsPROGBL  Auto
ect I have then declared all the variables as
float Materials 

float MaterialsPRO
ect I have then put the following at the start of the script
Materials = AAMBmaterialsGBL.getvalue ()

MaterialsPRO = AAMBmaterialsPROGBL.getvalue ()
ect and this at the end of my script
AAMBMaterialsGBL.setvalue (Materials)

AAMBMaterialsPROGBL.setvalue (MaterialsPRO)
ect The script works as usual when I activate the activator, and I can go through the menus and the variable amounts remain consistent throughout. However, when I leave the menu and re-activate the menu, all the variables have gone back to zero. This means the script is failing either at the point where the variables are set to the global variables at the start, or where the global variables are updated at the end. (or both). Now seriously, what am I doing wrong here, because this took a good hour or two and it's still not working. I know I used floats instead of ints, but that was just to cut out the awkwardness of swapping between the two- I have tried it with ints originally (using getvalueint and setvalueint) but this did not work either (same problem). My globals are all set up as "floats" (as apposed to shorts or longs) and none are set to constant. They all have a starting value of zero. PLEASE someone tell me where I'm going wrong here because it's driving me up the wall!!! EDIT: also, the syntax both you and the wiki suggest is
int myGoldAmount = LevelersMaxGoldGBL.GetValue()
Which I presumed means it should be used when you declare the variables, so instead of
float materials
you would have
float Materials = AAMBMaterialsGBL.getvalue()
However this came up with the following error:
AAMBcCharter2.psc(35,18): no viable alternative at input 'AAMBMaterialsGBL'
so, I tried using it during an Event, so instead of
AAMBMaterialsGBL.setvalue (Materials)
you would have
float AAMBMaterialsGBL.setvalue (Materials)

however THIS reported the following error:

AAMBcCharter2.psc(78,25): required (...)+ loop did not match anything at input '.'

So what on earth am I doing wrong HERE as well?

Edited by Mysterious Mr. Bear
Link to comment
Share on other sites

Man i just made a video tutorial on global variables but i can't get it to encode right -_- not that it was a good tutorial but it was alot easier to explain with it... anyway.

Do all of this Inside the Creation Kit.

Create your GlobalVariable - let's call it MyGlobal.

Then go to the script in which you want to use MyGlobal.

Add a property of type GlobalVariable, let's call that MyProperty and then click on Edit Value and browse to (or type) MyGlobal.

Now the created property will point to the global variable MyGlobal and can be used inside the script.

You have to add a property like this to every script in which you want to use MyGlobal.

so for example:


Scriptname GlobalSet extends ObjectReference

GlobalVariable Property MyProperty Auto  


Event OnActivate(ObjectReference akRef)

	MyProperty.SetValue(5)

	Debug.MessageBox("Set Value is " + MyProperty.GetValue())

EndEvent

MyProperty.SetValue(5) will not actually change the value of MyProperty, but the global it is pointing to, so in this case MyGlobal will be 5

Scriptname GlobalGet extends ObjectReference

GlobalVariable Property MyProperty Auto  


Event OnActivate(ObjectReference akRef)

	Debug.MessageBox("Get Value is " + MyProperty.GetValue())

EndEvent

MyProperty.GetValue() is the same, it will not read out it's value, but the value from MyGlobal which the property is pointing to. So here, if the GlobalSet script did run first, the messagebox would read "Get Value is 5"

I have no idea why it is how it is, but after a dreadful week of trial and error, this is how i found it works...

Hope this is understandable and helping :/

Edited by Eaglemania
Link to comment
Share on other sites

Ah of course!!! I forgot that things like references, objects, and apparently globals all had to be linked with the CK... I spent about a day finding that out when working with object enabling! Bloody hell... right, I'm going to add all of this globals the official way then :P

eye ya yeye.... I'd forgotten what working on the CK is like. If I'm not fixing a problem, I'm probably fixing a solution!

Thanks very much, sometimes it's these small little things that trip people (and bears) up. I'll post back here if it works (though I'm presuming it will, cant see anything else that could go wrong as williesea has ironed out a lot of possible problems allready...)

Link to comment
Share on other sites

Holy-waste-of-time, batman!

After ALL of this time, it turns out, by going into the CK and mapping the property of "charter" in my very original script I posted here, it would have fixed all of this from the start. The issue was that my script making these changes was linked to my script holding my variables via this "charter" property- by simply attaching my script making the changes to an object and assigning this property to the correct object in the CK, it would have worked fine without globals!

Ah well eye, at least it will work now I have followed Eagle's advice :) We really need a stickey''d "hints and tips" thread here, for all these little traps and potholes to trip up on that are too small to mention in a lesson or an indidual thread... but thankyou everyone, I swear this website patches up and fixes 50% of the scripts I make :P

Link to comment
Share on other sites

GOOD SWEET LORD OF MERCY.

It's STILL not working!!! How long is this going to MESS up for???

I have attached both scripts to objects, auto-filled BOTH scripts properties (and checked the were right), both scripts are RUNNING, but IT'S STILL NOT DETECTING THIS NUMBER AS A MINUS NUMBER!!!!

Right. I was still getting the daily messages BEFORE I followed these steps of object-attaching and property filling, and I still get it now. However, I added an activate event to the script that detects the minus number (the one that is not working) and yet when I activate the object, nothing happens. When I run ShowVariables, It comes up saying no papryus scripts are attached. Even with a clean save. There is surely some tom-foolery here, yet when I open the base object the script is attached and autofilled there, and when I open the reference the script is attached and autofilled THERE.

I'm going to try with a new object. But please for the love of god, let this work, because this is such a small little thing and it's held me back longer than everything in the mod combined.

Eagle, do you have that video on youtube or anything? Cos I'd love to see it, just to check I'm not being an idiot.

Link to comment
Share on other sites

Made a new object... no dice. What have I done wrong??

That was a genuine question, not a down on my knees, shaking my fist at the sky, scream of despair to the god of modding himself.

Actually, it was both.

EDIT:

.... this script extends a quest, I see.

As in, a quest that is not an object, I see.

And this thing I have been attaching it to is not a quest, I see. But an object.

I see.

Interesting.

Very interesting.

i-have-no-idea-what-im-doing-dog.jpg

Edited by Mysterious Mr. Bear
Link to comment
Share on other sites

Glorious. It's working. :jellytime:

Lesson I have learned: Spending a day of college grinding away at one problem does not result in it getting solved faster, it results in you making a thousand tiny mistakes you normally don't. Thankfully they are all fixed... for now....

Thankyou everyone for help and patience, and sorry for my idiotic spam... though I will not apologise for the dog picture, because it's pretty funny.

Mysterious Mr. Bear :D :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...