Globat int vs. local int
#1
Posté 15 octobre 2011 - 03:29
Atm I´m faced to a problem, I can´t understand. I working on an Inn, where a player can get a key for a bedroom during a conversation. Of course I don´t want to have multiple people in one room, so I set a global_int to 1, when the player gets a key. Other nodes in the conversation contain a condition, so that no other players can get the key, when the global int = 1, until the key gets back to the owner. So far the idea, but unfortunally it does not work as planned. Every node in the conversation that contains the condition to check the global int, is ignored in the conversation and the conversation stops immediatly.
I try to set a global int for this, because as far as I unterstand the global vs. local int. thing, a local int would only prevent the player, who got the key before from getting another key, while other players would be able to get a key for the same room, or did I misunderstand something?
#2
Posté 15 octobre 2011 - 04:31
It sounds like your test idea should work and I have done similar many times. I am guessing your problem is either in the test itself or the structure of the conversation. neither are easy to problem solve on the forum.
If you PM a link to the convo file I am happy to have a look for you.
in general though say your man has three rooms. You say.
Can I have a room?
Yes here's the key gc_local_int key 1 !1
Thank you good barman. ga_local_int key 1 =1
Yes here's the key gc_local_int key 2 !1
Thank you good barman. ga_local_int key 2 =21
Yes here's the key gc_local_int key 3 !1
Thank you good barman. ga_local_int key 1 =1
Sorry I don't have any rooms.
Here is my key back gc_local_int Key 1 =1
Thank you good sir, come again. ga_local_int key 1 =0
Thank you good barman.
Here is my key back gc_local_int Key 2 =1
Thank you good sir, come again. ga_local_int key 2 =0
Thank you good barman.
Here is my key back gc_local_int Key 3 =1
Thank you good sir, come again. ga_local_int key 3 =0
Thank you good barman.
Put the local int on the barkeeps tag.
What will happen here is the barkeep will first offer key 1, if it is gone the convo fall throguh to key 2 and then 3 if he has no keys he will say he has no rooms. The barkeep will always offer the lowest number key he has available.
the integer could equally be a global one, then you dont have to pin it on the barkeep.
At any time the player has a key he will be able to give it back.
Does that help at all?
PJ
#3
Posté 15 octobre 2011 - 04:43
I have already made one module and am 90% done with my second and I have never used a global int. I prefer locals because they are more specific because they are stored in a certain location. If you accidentally give two local integers the same name, but they are on different objects, it is no big deal because you look for those integers on a specific object. Also, this gives you more flexibility with scripting because you *can* give local integers the same name and put them on different objects and it works just fine.
Global integers will also work fine, but you have to make sure each one has a different name or else you will run into problems.
As far as I know, that is the only difference.
I am 99% sure that using global or local integers will make no difference to your inn key scripting as long as your naming conventions are correct.
On a side note, regarding your key situation, you could just make 3 different key blueprints in the toolset and actually give them to the player then use the script:
gc_item_count
in your conversation nodes to check for whether the pc or an npc has the key.
#4
Posté 15 octobre 2011 - 05:14
However I have never used a local int it any of my five modules. Which means i could be in for a rough ride when I make them a campaign
PJ
#5
Guest_Iveforgotmypassword_*
Posté 15 octobre 2011 - 05:17
Guest_Iveforgotmypassword_*
Sound advice, here's a quick solution.
If it's a one shot room entry ( until you pay again ) just give a key and remove it from the inventory when it's used ( check the remove key box on the door ). Then lock the door on leaving the inn. Script on the area exit section.
Global Int's are good for use in conversations what's happened previously instead of a journal entry, Local Int's are pretty much as the name suggests for local issues.
PJ156.. I doubt you'll have a problem on conversion I never have just so long as you remember them all, I've even used them for testing jumping into modules and setting them from a conversation so it seems you've played the other mods.
Modifié par Iveforgotmypassword, 15 octobre 2011 - 05:21 .
#6
Posté 15 octobre 2011 - 05:47
#7
Posté 15 octobre 2011 - 06:11
Globalint are dangerous as mister Rieder said, if you name 2 different things the same you are screwed.
#8
Posté 15 octobre 2011 - 06:26
However, using local variables in nwscript hardly even makes accessing them more difficult. You can store your variables on any object you'll be able to find later on--a creature, an item, an area, or even the module itself. Finding these objects is usually also not that hard--often it's as simple as getting the nearest object with a certain tag.
Of course, global variables have their place. I would suggest that you use them only if you have a specific reason to do so, and only if you don't intend to change their values often.
#9
Posté 15 octobre 2011 - 06:29
PJ156 wrote...
Either will work, it depends where you put the local int.
It sounds like your test idea should work and I have done similar many times. I am guessing your problem is either in the test itself or the structure of the conversation. neither are easy to problem solve on the forum.
If you PM a link to the convo file I am happy to have a look for you.
in general though say your man has three rooms. You say.
Can I have a room?
Yes here's the key gc_local_int key 1 !1
Thank you good barman. ga_local_int key 1 =1
Yes here's the key gc_local_int key 2 !1
Thank you good barman. ga_local_int key 2 =21
Yes here's the key gc_local_int key 3 !1
Thank you good barman. ga_local_int key 1 =1
Sorry I don't have any rooms.
Here is my key back gc_local_int Key 1 =1
Thank you good sir, come again. ga_local_int key 1 =0
Thank you good barman.
Here is my key back gc_local_int Key 2 =1
Thank you good sir, come again. ga_local_int key 2 =0
Thank you good barman.
Here is my key back gc_local_int Key 3 =1
Thank you good sir, come again. ga_local_int key 3 =0
Thank you good barman.
Put the local int on the barkeeps tag.
What will happen here is the barkeep will first offer key 1, if it is gone the convo fall throguh to key 2 and then 3 if he has no keys he will say he has no rooms. The barkeep will always offer the lowest number key he has available.
the integer could equally be a global one, then you dont have to pin it on the barkeep.
At any time the player has a key he will be able to give it back.
Does that help at all?
PJ
I made a similar conversation, with two differences. I have three
different blueprints, one for a room. The keys do not come from the
barkeeper`s inventory, the got created by ga_give_item.
I changed the
the ints from global to local, but it still doesn´t work. Every node
that has the condition to check the local int is completly ignored,
whether a player ordered a key yet, or not.
I set unique local ints for each room/key and the convo looks in essence like this:
I want the 1st room.
You do not have enough money. gc_check_gold >25
Great, here you have the key. gc_local_int string !1; ga_take_gold 25, ga_give_item Key Tag (This node is ignored)
--> Thank you. ga_local_int string =1
Sorry, this room is occupied yet. (This node always comes up, whether a player got a key - which is impossible atm, before, or not).
When the player wants to leave the Inn, he has to walk over a speaktrigger:
Sorry, you still got my key. gc_check_item (one for every key)
--> Sorry, here is your key.
---->As I remember you had Room 1? ga_check_item key1 tag
------>That´s right, here is the key.
-------->Thank you, Sir, please visit us again. ga_destroy_item keytag1 -1(all in inv.); ga_local_int string =0
---->As I remember you had Room 2? ga_check_item key2 tag
(The same as above, but with room/key/local int 2)
[color=rgb(0, 0, 0)">---->]As I remember you had Room 3? [/color]ga_check_item key3 tag[color="#0000ff"][/color]
(The same as above, but with room/key/local int 3)
Modifié par Barnabas2, 15 octobre 2011 - 06:34 .
#10
Posté 15 octobre 2011 - 08:51
I would check where you are putting the local int and is that the same as where you are testing it.
However if you are giving the player a unique tagged item then you can test for that as has been reccomended by the others. The local int is not needed.
Try testing it as a global int, then the location becomes irrelevant. If that works then it is where you are putting the integer rather than what it is.
Also check you have not ticked the not box by mistake, a not and a ! will cancel each other out I think.
PJ
BTW that is an expensive room
#11
Posté 15 octobre 2011 - 11:59
Barnabas2 wrote...
I changed the
the ints from global to local, but it still doesn´t work.
This suggests to me that the integers are not the problem. I say look elsewhere for reasons the node may not be firing.
Great, here you have the key. gc_local_int string !1; ga_take_gold 25, ga_give_item Key Tag (This node is ignored)
Look at the bolded and underlined above. If you are entering !1 for gc_local_int then that may be a problem. Try entering !=1. I'm not sure about this, but it may be the issue. Also, for testing purposes, you may want to try a simple 0 as well.
Modifié par M. Rieder, 16 octobre 2011 - 12:00 .
#12
Posté 16 octobre 2011 - 09:31
M. Rieder wrote...
Look at the bolded and underlined above. If you are entering !1 for gc_local_int then that may be a problem. Try entering !=1. I'm not sure about this, but it may be the issue. Also, for testing purposes, you may want to try a simple 0 as well.
I tried to set the condition to !=1, but it didn´t work neither. Then I set a condition for the sentence for occupied rooms with gc_local_int string =1. Now this sentence is ignored too, so it seems, that it is a problem with the local int. itself. Do I have to set the local int anywhere out of the conversation as well? Until now I only set local ints in the conversations self. For example I always use local ints at the beginning of a conversation, so that the NPC recognize the player after the first meeting. That always worked without a problem. The stuff with the keys is the first time I have these problems.
On a side note, regarding your key situation, you could just make 3
different key blueprints in the toolset and actually give them to the
player then use the script:
gc_item_count
in your conversation nodes to check for whether the pc or an npc has the key.
I think I´ll try that. For this, as far as I understand that, I have to set one of each key into the inventory of the barkeeper, do I? And the key must not be destroyed, when the PC leaves the area?
#13
Posté 16 octobre 2011 - 03:05
Barnabas2 wrote...
I tried to set the condition to !=1, but it didn´t work neither. Then I set a condition for the sentence for occupied rooms with gc_local_int string =1. Now this sentence is ignored too, so it seems, that it is a problem with the local int. itself. Do I have to set the local int anywhere out of the conversation as well? Until now I only set local ints in the conversations self. For example I always use local ints at the beginning of a conversation, so that the NPC recognize the player after the first meeting. That always worked without a problem. The stuff with the keys is the first time I have these problems.
If you don't set a local int, the engine defaults to 0 for its value. So you never have to initialize a local int as 0, you can just not initialize it. If all the variable names are correct and the objects you are storing them on exist and are correct, then I am mildly baffled at the problem.
I think I´ll try that. For this, as far as I understand that, I have to set one of each key into the inventory of the barkeeper, do I? And the key must not be destroyed, when the PC leaves the area?
I don't think you need to put the key in the barkeep's inventory, just create it on the PC the way you have been doing things. The only difference would be that instead of checking for a local int, you would check for the key on the player. Of course, this wouldn't help keep other players from getting a key from the inkeep, and that brings us back to the integers.
I'm not sure why the integers aren't working for you. From what you describe, the system should work. If you get stuck and can't make it work, let me know and maybe you can extract the convo in an .erf file and put up a dropbox or mediafire link and I'll have a look at it, if you want.
#14
Posté 16 octobre 2011 - 03:27
Can you put the convo on dropbox or simlar and link it. Either export it if you are working in .mod format or copy paste it from the folder?
PJ
#15
Posté 16 octobre 2011 - 05:28
M. Rieder wrote...
If you don't set a local int, the engine defaults to 0 for its value. So you never have to initialize a local int as 0, you can just not initialize it.
Yes, this brings up interesting issues in situations where you want to have a local var have a meaningful value that you want to treat as 0 but you want to know it's been initialized.
For example, when I stored custom faction reputations as integers, I wanted to be able to distinguish a value that had not been stored from a really terrible reputation. My solution was to never let a reputation get below 5 or so; the in-game effect was the same, but I was able to determine whether a variable had or hadn't been stored.
#16
Posté 17 octobre 2011 - 01:54
#17
Posté 17 octobre 2011 - 04:40





Retour en haut






