ok it's working now (I started writing off the top of my head inside of sublime so I ended up forgetting a few things like adding value of "x" to the VAnimationCurrentPosition & also forgot to use 2 == on an if query line)
all working now though.
script 1: the mainLoop handler & additional setup. (definition script)
-- init values for table tblMainLoop
local tblMainLoop = {}
tblMainLoop["vlf_scene"] = 0
tblMainLoop["vlf_state"] = 0
-- * let's create a function for updating the if query values for the mainLoop function for the vLoopFunc() function
function vl_toMainLoop(scene, state)
tblMainLoop["vlf_scene"] = scene
tblMainLoop["vlf_state"] = state
end
-- * let's create the onMainLoop function which handles all of our loop requests * --
function onMainLoop()
if tblMainLoop["vlf_state"] ~= 0 and game:getLink(VGameCurrentScene):getName() == tblMainLoop["vlf_scene"] then -- check if state isn't 0 & current scene is set scene else do nothing
vLoopFunc()
end
end
-- * let's create the mainLoop handler * --
registerEventHandler("mainLoop", "onMainLoop")
script 2: the generic movement script (definition script)
--[[
Generic Vertical Loop Script for Marvel
Written by AFRLme
-- * --
label@alternatingfrequencies.com, aim/skype: AFRLme
--]]
-- * let's create some init variables for the script * --
local min = 0 -- highest point of y on scene you want animation to move to
local max = 0 -- lowest point of y on scene you want animation to move to
local speed = 0 -- set speed of animation movement (add a value between 1-10)
local state = 0 -- the direction the animation should move to (0=static, 1=up, 2=down)
local scene = 0 -- add the scene containing the animation
local anim = 0 -- link to the animation you want to move
local current_scene = 0 -- check the current scene name
-- * let's create a function for setting up the script * --
function vInitSetup(mn, mx, scn, ani, spd, sta)
min = mn -- set min value position (top)
max = mx -- set max value position (bottom)
scene = getObject("Scenes[" .. scn .. "]"):getName() -- set scene
anim = getObject("ActiveAnimations[" .. ani .. "]") -- set animation
-- * --
if spd < 1 then spd = 1 end -- check speed isn't less than 1
if spd > 10 then spd = 10 end -- check speed isn't more than 10
speed = spd -- set speed
-- * --
if sta < 0 then sta = 0 end -- check state isn't less than 0
if sta > 2 then sta = 2 end -- check state isn't more than 2
state = sta -- set movement direction (static, up, down)
-- * --
vl_toMainLoop(scene, state) -- send required if query variables to another function we can use in onMainLoop function
-- * --
--print("min: " .. mn .. ", max: " .. mx .. ", speed: " .. spd .. ", state: " .. sta .. ", scene: " .. scn .. ", animation: " .. ani)
--print("scene: " .. scene:getName() .. ", current scene: " .. current_scene .. "!")
end
-- * let's create a function for adjusting speed animation moves up & down (value between 1 & 10)
function vSpeedVal(i)
if i < 1 then i = 1 end -- check i isn't less than 1
if i > 10 then i = 10 end -- check i isn't more than 10
speed = i
end
-- * let's create a function for adjusting direction animation should move to (0=static, 1=up, 2=down) * --
function vLoopState(i)
if i < 0 then i = 0 end -- check i isn't less than 0
if i > 2 then i = 2 end -- check i isn't more than 2
state = i
end
-- * let's create the vertical loop function which we will be using to move the animation up & down * --
function vLoopFunc()
local tblAnim = {} -- create local table
tblAnim["_temporary_"] = "" -- set table as temporary
tblAnim["pos"] = anim:getPoint(VAnimationCurrentPosition)
-- * check if state is 1 & animation position is more than min pos & if so then make it move * --
if state == 1 and tblAnim["pos"].y > min then anim:setValue(VAnimationCurrentPosition, {x=tblAnim["pos"].x, y=tblAnim["pos"].y - 1}) end
if state == 1 and tblAnim["pos"].y <= min then state = 2 end -- check if animation position is less than or equal to min pos & change direction
-- * check if state is 2 & animation position is less than max pos & if so then make it move * --
if state == 2 and tblAnim["pos"].y < max then anim:setValue(VAnimationCurrentPosition, {x=tblAnim["pos"].x, y=tblAnim["pos"].y + 1}) end
if state == 2 and tblAnim["pos"].y >= max then state = 1 end -- check animation position is more than or equal to max pos & change direction
end
P.S: you are only allowed one of each event handler per project, so if you are already using a script which contains a mainLoop handler then you need to add the first part of the script into wherever the mainLoop function is located & also copy/paste the content inside of the "onMainLoop()" function into whatever your mainLoop function is called & then remove the registerEventHandler line & the onMainLoop part of my script.
Also before this script will work you need to create an execute a script action part in an at begin of scene action for each scene in which you want to move an animation up/down...
execute a script: vInitSetup(mn, mx, "scn", "ani", spd, sta)
mn = integer value (highest point of scene you want animation to move up towards)
mx = integer value (lowest point of scene you want animation to down towards)
scn = string value ("write_scene_name")
ani = string value ("write_animation_name")
spd = integer value (speed animation should move on y axis (number between 1 & 10)
sta = integer value (direction animation should move: 0=static, 1=up, 2=down)
-- example
vInitSetup(300, 600, "1_first_scene", "skully_1", 3, 1)