I've been trying all night to see if I can get this working, but without any luck.
Is there anyway to access a global variable from another script?
| Login to reply | Page: « < 1 of 1 > » |
| 13 Jun 2010 - 06:48 | 2706 |
| Vatiken New Member ![]() Joined: 03 Jul 2008 Posts: 78 | Accessing Global from another Script I've been trying all night to see if I can get this working, but without any luck.
Is there anyway to access a global variable from another script? |
![]() |
| 13 Jun 2010 - 19:29 | 2707 |
| Rumble Contributor ![]() Joined: 04 Jul 2007 Posts: 592 | Yup, help files and examples under HELP GLOBAL:
help global
GLOBALS GLOBAL-VARIABLES GLOBAL-VARS GVARS TRIGEDIT-GLOBALS TRIG-GLOBALS
Usage: global <variablename>
Global variables allow a room/mob/obj trigger variable to be used by another
trigger on the same room/mob/obj. i.e. a bribe trigger could global that the mob
has_been_bribed then when a player tries to leave the mobs leave trigger would
check the global variable to allow or prevent passage accordingly.
* To make a variable 'reachable' from other triggers it has to be made 'global'.
* In this case I make a local known var %has_bribed_guard% and make it global.
* It is a good idea to use this in conjunction with context.
set has_bribed_guard 1
global has_bribed_guard
Globals can be checked by varexists: if %actor.varexists(<variable>)%
Global variables should not be used when you want to remember something about a
player. To save something to a players file for future use always use REMOTE.
Examples: TSTAT 23612, 23613, 23614
See also: REMOTE, VARIABLES, CONTEXT
> tstat 23612
Name: 'Lieutenant Door Bribe - M23608', VNum: [23612], RNum: [ 2667]
Trigger Intended Assignment: Mobiles
Trigger Type: Bribe , Numeric Arg: 1, Arg list: None
Commands:
* By Welcor of The Builder Academy tbamud.com 9091
wait 1
* The price is 400 coins to pass. Player must 'give 400 coin leader.'
if %amount% < 400
say Did you really think I was that cheap, %actor.name%.
snarl
else
* Context saves the global with the players ID so multiple players can bribe.
context %actor.id%
* Set the variable to a value, 1 for YES.
set has_bribed_guard 1
* Global it! You can now 'stat leader' and see it listed.
global has_bribed_guard
whisper %actor.name% Enter when you're ready. I'll lock the door behind you.
unlock door
end
> tstat 23613
Name: 'Lieutenant Door Bribe 2 - M23608', VNum: [23613], RNum: [ 2668]
Trigger Intended Assignment: Mobiles
Trigger Type: Door , Numeric Arg: 100, Arg list: None
Commands:
* By Welcor of The Builder Academy tbamud.com 9091
* Allows more than one instance of this trigger to run.
context %actor.id%
* Checks a global variable to see if this mob has been bribed. TSTAT 23612.
if %has_bribed_guard%
* Let the player through, he's paid.
return 1
* Don't bother continuing the trig, just stop it.
halt
end
* If the player tries to pick the lock catch him!
if %cmd% == pick
* Stop them! Return 0 prevents the command from going through.
return 0
wait 1
say No way, you don't fool me, %actor.name%.
* If mob can see the player, kill him!
if %actor.canbeseen%
mkill %actor%
end
end
> tstat 23614
Name: 'Lieutenant Leave - 23608', VNum: [23614], RNum: [ 2669]
Trigger Intended Assignment: Mobiles
Trigger Type: Leave , Numeric Arg: 100, Arg list: None
Commands:
* By Welcor of The Builder Academy tbamud.com 9091
* If the player is trying to leave to the East.
if %direction% == east
context %actor.id%
* If they have bribed let them through and forget them.
if %has_bribed_guard%
unset has_bribed_guard
* Let the command go through. Halt the trig, its over.
return 1
halt
end
* They haven't paid, stop them.
%send% %actor% You try to leave, but %self.name% stops you.
return 0
__________________ Rumble The Builder Academy tbamud.com 9091 ![]() |
![]() |
| 14 Jun 2010 - 00:47 | 2709 |
| Vatiken New Member ![]() Joined: 03 Jul 2008 Posts: 78 | Thanks, but unfortunately that wasn't what I was looking for. I was originally under the impression that the global variables were accessible globally, as in by any script, but it appears they are only accessibly by scripts attached to the same mob/obj/room.
An example of what I would be trying to accomplish would be the player gives MOB X an object that makes fire rain from the sky. The trigger would set a global variable like 'fire_in_the_sky 1', and then other room triggers around the game would drop random fire chunks throughout the world after checking for that global variable. |
![]() |
| 14 Jun 2010 - 01:23 | 2710 |
| Fizban Regular Poster ![]() Joined: 05 Jul 2007 Posts: 244 | Quote Vatiken:
Thanks, but unfortunately that wasn't what I was looking for. I was originally under the impression that the global variables were accessible globally, as in by any script, but it appears they are only accessibly by scripts attached to the same mob/obj/room. An example of what I would be trying to accomplish would be the player gives MOB X an object that makes fire rain from the sky. The trigger would set a global variable like 'fire_in_the_sky 1', and then other room triggers around the game would drop random fire chunks throughout the world after checking for that global variable. Sounds more like what you want is a remote variable. set fire_in_the_sky 1 remote fire_in_the_sky %actor.id% you can then check for the variable from another script with the following: if %actor.varexists(fire_in_the_sky)% __________________ ![]() |
![]() |
| 14 Jun 2010 - 03:16 | 2711 |
| Vatiken New Member ![]() Joined: 03 Jul 2008 Posts: 78 | Unfortunately you would still need that %actor%. What I was looking for was a game wide variable that would result in a player on one side of the world being affected by another players actions on the opposite side. I've resulted in adding some hard coded variables that can be accessed and changed through dg_scripts to suit my needs. Not as ideal and flexible as I'd like, but it should work for the time being. |
![]() |
| 14 Jun 2010 - 18:27 | 2713 |
| welcor Regular Poster Joined: 04 Jul 2007 Posts: 262 | AFAIR, I added something to do this,
remote varname %global% corresponding with %global.varname% IIRC, of course. __________________ You know who I am. |
![]() |
| 15 Jun 2010 - 01:41 | 2715 |
| Vatiken New Member ![]() Joined: 03 Jul 2008 Posts: 78 | Thanks welcor, that seems to be working. Last edited by Vatiken (15 Jun 2010 - 01:58) |
![]() |
| Login to reply | Page: « < 1 of 1 > » |