It is currently March 28th, 2024, 4:41 pm

stuck with script :S

Discuss the use of Lua in Script measures.
Post Reply
viper
Posts: 17
Joined: July 8th, 2012, 7:03 pm

stuck with script :S

Post by viper »

ok i am new to LUA so please if possible spells things out for me lol

basically what i am trying to do is
IF X1 == X2 and Y1 == Y2 then
do nothing
else
(change X1 to == X2) and (change Y1 to == Y2)

here is the code atm

Code: Select all

function Initialize()

	msXheight = SKIN:GetVariable('#CURRENTCONFIGX#')
	msYwidth = SKIN:GetVariable('#CURRENTCONFIGY#')
end -- function Initialize

function Update()

if sType == msXheight then
		exit
	else
		SKIN:Bang('!WriteKeyValue variables LocationX #CURRENTCONFIGX# #CURRENTPATH#variables.inc')
		
	end	
if sLabel == msYwidth then
		exit
	else
		SKIN:Bang('!WriteKeyValue variables locationY #CURRENTCONFIGY# #CURRENTPATH#variables.inc')
		SKIN:Bang('!Refresh')
	return '99'
end -- function Update
basically i want the script to check the skins postion on the screen check it against a the relevant X and Y variables, and if they are not both equal then change them so the screen x and y values are equal to the variable x and y values

thank you for any help given :D
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am
Contact:

Re: stuck with script :S

Post by Kaelri »

Ok, there are a couple of syntax problems here:

- sType and sLabel are never defined.
- You don't need pounds signs (#) in GetVariable().
- You never ended your last "if" statement. I think you confused it with the "end" for Update().
- "exit" is not a standard Lua command for if-statements. And if you're not actually doing anything when the two variables are equal (only when they're not equal), you might as well just use one condition.
- You will probably have some errors unless you put "#CURRENTPATH#variables.inc" in double quotes.

In addition, I can see some conceptual problems:

- You probably want to get #CURRENTCONFIGX# and #CURRENTCONFIGY# in Update(), not Initialize(). Otherwise, you will only be able to use the coordinates from when the skin is first loaded.
- Finally, this probably doesn't affect how the code works, but generally, "x" is associated with horizontal space (i.e. widths), and "y" with vertical space (i.e. heights).

I've cleaned up the most basic mistakes below, but there are still some missing elements you will need to provide.

Code: Select all

function Update()

	msXwidth = SKIN:GetVariable('CURRENTCONFIGX')
	msXheight = SKIN:GetVariable('CURRENTCONFIGY')

	--These have to be defined as something before you can use them:
	sType =
	sLabel =

	if sType ~= msXwidth then
		SKIN:Bang('!WriteKeyValue Variables LocationX #CURRENTCONFIGX# "#CURRENTPATH#variables.inc"')
	end   
	
	if sLabel ~= msXheight then
		SKIN:Bang('!WriteKeyValue Variables LocationY #CURRENTCONFIGY# "#CURRENTPATH#variables.inc"')	
	end

	SKIN:Bang('!Refresh')
	return '99'
	
end -- function Update
viper
Posts: 17
Joined: July 8th, 2012, 7:03 pm

Re: stuck with script :S

Post by viper »

thank you very much i can see my very silly mistakes :D was 3am when i tried writing it :D tired and coding not a good idea


as for the stupid mistake of height and width lol embarrassed is the only word i can use there :oops:

but thank you anyway for you help Kaelri
Post Reply