AL/Global problems.[>answered: cheers cycrow!<]

The place to discuss scripting and game modifications for X³: Reunion.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

User avatar
ninjitsumonk
Posts: 1874
Joined: Thu, 1. Mar 07, 09:21
x3

AL/Global problems.[>answered: cheers cycrow!<]

Post by ninjitsumonk »

Code: Select all

...
else if $al.Event == 'timer' ...
$wave = get global variable: name= $plugin.wave
if $wave == -1 OR null ...
Start:
$y = = random value from 0 to 16 -1
$x = = random value from 0 to 21 -1
$sector = get sector from univers index: x= $x, y= $y
if sector == null
goto lable start
end
$wave= 3 ...
Else
$x = get global variable: name= $plugin.x
$y = get global variable: name= $plugin.y
end
if $threat <= 19 ...
Inc $threat=
=[THIS] - > call sript al.khaak.handler : threat level of khaak= $threat wave timeout=$wave  x= $x  y= $y
else
=[THIS] - > call script al.khaak.handler : threat level of khaak= $threat wave timeout=$wave  x= $x  y= $y
end
end
return null
now for my problem i've got the al.khaak.handler to relay $sector and $wave to my message inbox and from what i can see the $wave function is fine and perfect but the $sector is not. This is what my inbox looks like:
-1
kingdom end
0
power circle
1
the hole
2
a random sector
-1
kingdom end
0
power circle
1
the hole
2
a random sector
etc..
So why isn't it giving me the same sector 4 times like i want it to? Can anybody see any problems? i've checked the handler script and it's got nothing to do with the problem. It just uses the co-ordinates provided to get the sector and then run the ship spawning script which again works fine.
Thanks.
Last edited by ninjitsumonk on Tue, 24. Jul 07, 22:31, edited 1 time in total.
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22415
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

its quite messy, and pretty much limited.

there are much better ways to find a random sector.

theres actually a command for it.

also, y have u hardcoded the numbers for the universe ?
its bound to miss some of the sectors.

best way, would be to use the find random sector, set the start sector to anything, usually i use the play ships sector. If you want to pick from all sectors, set the jump range to something high, 50 will get all the sectors in the standard game and should get most if not all in custom maps. Althou i tend to use 100 to be sure.

also, jumping around the script using gotos are not always the best, something like that should be done in a while loop.
User avatar
ninjitsumonk
Posts: 1874
Joined: Thu, 1. Mar 07, 09:21
x3

Post by ninjitsumonk »

Okay, so note to self clean up script :P
right but why would the random work for the first sector but then return the same three for the next two?
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22415
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

maybe its got something to do with $wave

whats that actually for ?

and whats it being set to.

the statment $wave = 3, seems to have to effect in the script, unless theres more to it that u've posted ?

once last thing, your varibles are done wrong. U dont use varibles as the name, unless u have set them up to do it.

have u defined $plugin.ware, $plugin.x, and $plugin.y anywhere ?
User avatar
ninjitsumonk
Posts: 1874
Joined: Thu, 1. Mar 07, 09:21
x3

Post by ninjitsumonk »

No, i thought you just put it in and thats how it worked? Okay maybe i jumped in a little too deep. Can you point me to a tutorial on globals or tell me how?
Wave doesnt do anything more than tell the script when to change the attack. I just set it to three for now so i can check the effect, when it gets to -1 it's meant to change the sector that's under attack.
Plugin.x, plugin.y and plugin.wave are all defined as global variables in the al.khaak.handler and basically just hold the value 'x' and 'y' respectively.
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22415
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

ur not far off. The problem is that ur treating the global/local varibles, as the same thing as the varibles within a script, they are not the same thing.

the name argument, is not a varible, its a string.

i dont know if u know what a hash table is, but thats basically how the global varibles work.

a hash table stores data to specific strings.

ie, you have a string "string1" and assign a value to it.
then when you want to use that again, it searchs for "string1" and returns the stored value.

to change then ame argument from a varible to a string, for both set and get. IE,

Code: Select all

$wave = get global varible, name = 'plugin.wave'
althou, as a convention, i would add the name of the script as well, its not required, its just a convention

say the script is called khaak invasion, u could have something like

Code: Select all

$wave = get global varible, name = 'khaakinvasion.wave'
$wave = get global varible, name = 'plugin.khaakinvasion.wave'
$wave = get global varible, name = 'khaak.wave'
$wave = get global varible, name = 'plugin.khaak.wave'
some authors add thier initials as well, this just makes it so no other users will user the same varible causing the problems, this is very rare, but it is possible.

the problem your having, is that when you get or set the varible, what happens is the varible "$plugin.wave" will return null, as will $plugin.x, and $plugin.y

which means, that when all your varible calls basically end up looking like this

Code: Select all

$wave = get global varible, name = NULL
as they are all null, they are all effectivly the same varible, so they will replace each other, so, the value that it returns, will be the last one that was set.

say u have this

Code: Select all

set global varible, name = $plugin.wave, value = 1
set global varible, name = $plugin.x, value = 2
set global varible, name = $plugin.y, value = 3
and u call them back again

Code: Select all

$wave = $get global varible, name = $plugin.wave
$x = $get global varible, name = $plugin.x
$y = $get global varible, name = $plugin.y
u would expect them to be, $ware = 1, $x = 2, $y = 3.

but what you actually get is, $ware = 3, $x = 3, $y = 3.

which is most likly where your problems first arrise

hopefully that made abit of sense
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22415
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

one more point, varibles like integers and strings are passed by value.

which means if u have code like this

Code: Select all

set global varible, name = 'plugin.wave', value = 1
$wave = get global varible, name = 'plugin.wave'
inc $wave
$wave = get global varible, name = 'plugin.wave'
$wave will = 1, not 2 like u might have hoped, you need to set it again

Code: Select all

set global varible, name = 'plugin.wave', value = 1
$wave = get global varible, name = 'plugin.wave'
inc $wave
set global varible, name = 'plugin.wave', value = $wave
$wave = get global varible, name = 'plugin.wave'
if its an array, its different, as its only a pointer to the objects. If you set the global varible as the array, and then add a new element to that array. You dont have to set the varible again for it to work
User avatar
ninjitsumonk
Posts: 1874
Joined: Thu, 1. Mar 07, 09:21
x3

Post by ninjitsumonk »

Ah! So basically global vars are set up and called exactly like the arguements. That explains a lot.
Your a miracle worker Cycrow, owe ya one.
Btw nice site, very helpful, added to my favourites straight away!
Thanks again.
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22415
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

This page might be useful for users to learn about global varibles.

if you have no objectsions, ill add it to the tutorials sticky
User avatar
ninjitsumonk
Posts: 1874
Joined: Thu, 1. Mar 07, 09:21
x3

Post by ninjitsumonk »

Be my guest, I agree completely.

Return to “X³: Reunion - Scripts and Modding”