User Tag List

Results 1 to 8 of 8

Thread: Easy script system

  1. #1
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleSWF Export ModuleUnicode Add-on
    Boba Fonts's Avatar
    Join Date
    Jan 2009
    Location
    Northern Italy
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Easy script system

    For my point&click adventure I'd like to create a very simple custom script system that allows me to make characters walk, speak and do other animations during cutscenes without the need to specify each time, for each action, the same events. I could have a dozen of general events and then, for each cutscene, a script with a list of functions that MMF can interpret.
    I imagine something as:

    Character.Walk (160,204)
    Character.Animate ("Crouch down")
    Character.Say ("There's nothing here, let's try there")
    Character.Walk (190,136)
    Character.Say ("Hmm, someone's approaching me")
    Music.Play ("Music4.ogg")
    Wait.Time (60)
    Character2.Walk (214,140)
    Character2.Say ("Hello!")

    etc.
    Which is the best (and the easiest) way to achieve that?

  2. #2
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleSWF Export ModuleUnicode Add-on
    Looki's Avatar
    Join Date
    Aug 2006
    Location
    Karlsruhe, Germany
    Posts
    3,741
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)

    Re: Easy script system

    XLua - An extension that can interpret lua scripts.
    Your pseudocode is valid lua code, so the syntax should work for you.
    Prepare for a challenge, though, it won't be easy to make this - I might have time to set up an example though.
    The biggest problem is that when the Walk() function is called, you have to halt the script until the player has finished walking.

    For lua help, we have this forum.

  3. #3
    Clicker Multimedia Fusion 2
    dragonguy's Avatar
    Join Date
    Apr 2008
    Location
    RULE BRITANNIA!
    Posts
    3,071
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Easy script system

    Never done or thought of anything like that but I'll take out a hammer and give it a little whack!

    Create a List object and put your commands in to that hten make a Counter, make it so that it follows each command at an interval or wait for the last action to be finished, then add to the Counter to make it do the next thing.

    You will have to set-up a system of transferring each individual command to the alterable string/value object of the objects and then after that is finished add 1 to the counter, tokens is recommended as your command language is a bit difficult, I highly recommend to use 'Only one action when the event loops' an aweful lot.

    [color:#FF0000]There is no easy way to do this without Lua or something![/color]

  4. #4
    Clicker Multimedia Fusion 2SWF Export Module

    Join Date
    Sep 2006
    Posts
    1,544
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Easy script system

    An often easier way to do it is to align your script along timesteps, rather than simple 'in order' actions. This can remove the need for putting "Wait(30)" or whatever all over your script, and makes the xlua code much less of a headache.

    The runtime could simply fill a table with those events, populate another table with 'active' events, and then run all the events for that frame. Particularly if you are using a movement system that moves object "O" inbetween point "A" and "B" in "T" frames, its exceptionally easy to set up- you'd just set the position to be a percentage of the distance between the points.


    If I were setting it up, which I will be later this week, the syntax would look like:

    --CreateRoutine(Event ID) : Registers new event table
    --Event($ EventType, # TargetID, # Duration, # ValueA, #ValueB... etc)

    --ex. Event("Walk"..) -> Walk(TargetID, 20 Duration, X = 234, Y = 64)

    CreateRoutine(1)
    Event("Walk", 1, 20, 234, 16)


    I'm not entirely sure xlua allows overloading functions, so I'd probably have to have a finite number of inputs into the Event() call, but thats life. ID would probably be one of those for consistency.

  5. #5
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleSWF Export ModuleUnicode Add-on
    Boba Fonts's Avatar
    Join Date
    Jan 2009
    Location
    Northern Italy
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Easy script system

    Thank you all.

    Quote Originally Posted by Looki
    The biggest problem is that when the Walk() function is called, you have to halt the script until the player has finished walking.
    That could be a problem, since I need to be able to do two or more things at the same time. In the Event Editor I can have two characters walking simultaneously, or a character walking AND speaking; so why should I give up such a chance?
    I've already got the XLua extension but I was reluctant to use it, scared by the idea to learn a new scripting language.
    I love the simplicity of the Event Editor and my dream is to create a custom system, I mean a very simple one, without particularly advanced features.
    The idea of using a List Object sounds good, sounds basic (and I must do basic things in my scripts), but at the moment I'm puzzled and can't figure out which way is the best one.
    I'm open to examples, if you would be so nice to take time for those!

  6. #6
    No Products Registered

    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Easy script system

    You will need to use Lua im affraid. I have played with something similar before and its certainly possible, but be prepared to do some work and lots of testing/debugging :P

    If you are having multiple objects you will also need to give them their own ID so you can do code for different objects at once.
    You could store each object in a LUA table along with it's state.
    For exampple, you could do this for the walk command

    event("Walk",ID,xpos,ypos,speed)

    Then you set up an event in MMF which will pick the object via ID and then set its destination to xpos/ypos with a movement speed. You can store this info in the objects alterable values then MMF can handle the movement side of things, while LUA is simply allowing you to control it in a script like manner.

    Once you learn the LUA syntax and how it works with MMF you should be OK

  7. #7
    Clicker Multimedia Fusion 2SWF Export Module

    Join Date
    Sep 2006
    Posts
    1,544
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Easy script system

    Its still a fair bit of work. I created this entirely today, if you want to take a look at it. Its fairly commented, but I'm afraid it won't be too grokkable. But this is a scripting system that reads in a text file and lets me activate that script and apply it at any time (and once I've spruced it up, will work in reverse too).

    Feel free to use any bits or pieces, or just learn from it

    Code:
    --	List of loaded scripts and their parameters by time value
    --	3 Dimensional array.
    --	First : Script Name
    --	Second: Time Value
    --	Third: Parameters
    --		(String,Number,Number) -> @Value@
    scriptArray = {};
    
    
    --	List of currently active event indexes
    --	1 Dimensional array
    --	First: Index of active event
    --		(Number) -> @Value@
    eventArray = {};
    
    
    --	List of current script's time values
    --	1 & 2 Dimensional array
    --	First: Index of active script's time value
    --	also
    --	First: Name of script
    --	Second: Index of time value
    --		(Number) -> @Bool@
    --		(Name,Number) -> @Bool@
    scriptTimeArray = {};
    for k=1, 128 do
    	scriptTimeArray[k] = 0;
    end
    
    
    --	1 Dimensional array
    --	Ties tag name to object ID #
    --		(String) -> @Value@
    tagArray = {};
    
    
    --	Currently active script string
    --	@String@
    currentScript = "";
    
    
    --	Current frame time
    --	@Value@
    currentTime = 0;
    
    
    --	Number of active events
    --	@Value@
    currentActive = 0;
    
    
    --	Initializes a new script with the given name
    --		(string) -> @LUA@
    function initScript(Name)
    	currentScript = Name;
    	scriptArray[currentScript] = {};
    	scriptArray[currentScript]["Max"] = 0;
    	scriptArray[currentScript]["Number"] = 0;
    	scriptTimeArray[currentScript] = {};
    end
    
    
    --	Adds an event to currently active script
    --		(String,Number,Number,Number,Number,Number,Number,Number,Number,Number,Number) -> @LUA@
    function addEvent(Name, Time, Duration, P1, P2, P3, P4, P5, P6, P7, P8)
    	scriptArray[currentScript][Time] = {};
    	scriptArray[currentScript][Time][1] = Name;
    	scriptArray[currentScript][Time][2] = Duration;
    	scriptArray[currentScript][Time][3] = P1;
    	scriptArray[currentScript][Time][4] = P2;
    	scriptArray[currentScript][Time][5] = P3;
    	scriptArray[currentScript][Time][6] = P4;
    	scriptArray[currentScript][Time][7] = P5;
    	scriptArray[currentScript][Time][8] = P6;
    	scriptArray[currentScript][Time][9] = P7;
    	scriptArray[currentScript][Time][10] = P8;
    	if Time + Duration > scriptArray[currentScript]["Max"] then
    		scriptArray[currentScript]["Max"] = Time + Duration;
    	end
    	tempv = scriptArray[currentScript]["Number"] + 1;
    	scriptArray[currentScript]["Number"] = tempv;
    	scriptTimeArray[currentScript][tempv] = Time;
    end
    
    
    --	Tags an object based on Alterable String T
    --		(String) -> @LUA@
    function tagObject(Name)
    	for k=1, maxObjects do
    		if objectArray[k] == 1 then
    			if Name == mmf.Object.GetString(k,5) then
    				tagArray[Name] = k;
    				return;
    			end
    		end
    	end
    end
    
    
    --	Untags all objects
    --	NOTE: INVOKE THIS ONLY AFTER FULL ROTATION THROUGH TIME CYCLE
    --	IN A ZERO-TAG ZONE
    --	Otherwise, rewinding logic would get all screwy
    --		() -> @LUA@
    function resetTags()
    	tagArray = {};
    end
    
    
    --	Activates a script
    --		(String) -> @LUA@
    function activateScript(Name)
    	currentScript = Name;
    	currentTime = 0;
    	for j=1, 128 do
    		scriptTimeArray[j] = 0;
    	end
    	tempv = 0;
    	for k=1, scriptArray[currentScript]["Number"] do
    		tempv = scriptTimeArray[currentScript][k];
    		scriptTimeArray[tempv] = 1;
    	end
    end
    
    
    --	Activates a script from MMF
    --		() -> @LUA@
    --		(String)
    function activateScriptMMF(Name)
    	currentScript = mmf.LocalStore.GetString(1);
    	currentTime = 0;
    	for j=1, 128 do
    		scriptTimeArray[j] = 0;
    	end
    	tempv = 0;
    	for k=1, scriptArray[currentScript]["Number"] do
    		tempv = scriptTimeArray[currentScript][k];
    		scriptTimeArray[tempv] = 1;
    	end
    end
    
    
    --	Reactivates a script
    --		() -> @LUA@
    --		(String)
    function reactivateScript()
    	currentScript = mmf.LocalStore.GetString(1);
    	currentTime = scriptArray[currentScript]["Max"];
    end
    
    
    --	Executes active script forwards at given time value
    --	Executes open events forwards at given time value
    --		() -> @MMF@
    function forwardScript()
    	if currentTime > scriptArray[currentScript]["Max"] + 1 then
    		DoCall("deactivateScript");
    		if currentActive > 0 then
    			DoCall("Sound");
    		end
    		return;
    	end
    	if scriptTimeArray[currentTime] == 1 then
    		currentActive = currentActive + 1;
    		eventArray[currentActive] = currentTime;
    	end
    	currentTime = currentTime + 1;
    	if currentActive == 0 then
    		return;
    	end
    	tempv = 0;
    	k = 1;
    	while k <= currentActive do
    		tempv = eventArray[k];
    		type = scriptArray[currentScript][tempv][1];
      		if (_G[type]~=nil) then                 
       			_G[type ](tempv);
      		end
    		if currentTime >= (tempv + scriptArray[currentScript][tempv][2]) then
    			removeActive(k);
    			DoCall("number",currentTime);
    			k = k - 1;
    		end
    		k = k + 1;
    	end
    end
    
    
    --	Removes an event from the eventArray, lowering all above it
    --		(Number) -> @LUA@
    function removeActive(Numb)
    	currentActive = currentActive - 1;
    	for k=Numb, currentActive do
    		eventArray[k] = eventArray[k+1];
    		eventArray[k+1] = 0;
    	end
    end
    
    
    --	Executes active script reverse at given time value
    --	Executes open events reverse at given time value
    --		() -> @MMF@
    function reverseScript()
    end
    
    
    function testthis()
    	DoCall("number", tagArray["Player"]);
    end
    
    -- #########################   SCRIPT FUNCTIONS   ##########################
    
    
    --	Moves object ID from point A to B by percent
    --		(Number) -> @MMF@
    --		(Name, Ax, Ay, Bx, By)
    function eventMove(Event)
    	percent = (currentTime - Event) / scriptArray[currentScript][Event][2];
    	Ax = scriptArray[currentScript][Event][4];
    	Ay = scriptArray[currentScript][Event][5];
    	Bx = scriptArray[currentScript][Event][6];
    	By = scriptArray[currentScript][Event][7];
    	Px = (Bx - Ax) * percent + Ax;
    	Py = (By - Ay) * percent + Ax;
    	Name = scriptArray[currentScript][Event][3];
    	tagName = tagArray[Name];
    	mmf.Object.SetPosition(tagName, Px, Py);
    	if Name == "Player" then
    		mmf.Object.SetValue(tagName, 1, Px * 1000);
    		mmf.Object.SetValue(tagName, 2, Py * 1000);
    	end
    end
    
    
    --	Deactivates camera control
    --		(Number) -> @MMF@
    --		()
    function eventLockCamera(Event)
    end
    
    
    --	Activates camera control
    --		(Number) -> @MMF@
    --		()
    function eventUnlockCamera(Event)
    end
    
    
    --	Deactivates player control
    --		(Number) -> @MMF@
    --		()
    function eventLockPlayer(Event)
    end
    
    
    --	Activates player control
    --		(Number) -> @MMF@
    --		()
    function eventUnlockPlayer(Event)
    end
    
    
    --	Moves camera from point A to B by percent		
    --		(Number) -> @MMF@
    --		(Ax, Ay, Bx, By)
    function eventCameraMove(Event)
    end
    
    
    --	Makes an object play a given animation sequence
    --		(Number) -> @MMF@
    --		(Name, Anim)
    function eventAnim(Event)
    end
    
    
    --	Make an object play a given animation frame
    --		(Number) -> @MMF@
    --		(Name, Frame)
    function eventAnimFrame(Event)
    end
    
    
    --	Set a value of an object
    --	0-based index
    --		(Number) -> @MMF@
    --		(Name, Index, Value)
    function eventSetValue(Event)
    end
    
    
    --	Set a flag of an object
    --		(Number) -> @MMF@
    --		(Name, Index, Flag)
    function eventSetFlag(Event)
    end
    
    
    --	Destroy an object
    --		(Number) -> @MMF@
    --		(Name)
    function eventDestroy(Event)
    end
    
    
    --	Set quest flag on or off
    --		(Number) -> @MMF@
    --		(Flag)
    function eventQuest(Event)
    end


    note: alot of that is obviously unfinished skeleton code

  8. #8
    No Products Registered

    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Easy script system

    Wow...
    Can you post an MMF example of this working?

Similar Threads

  1. Automated Challenge / Response system - PHP Script?
    By ratty in forum Paid Design & Development Requests
    Replies: 8
    Last Post: 19th February 2014, 08:11 PM
  2. php scores script
    By RhysD in forum SWF/Flash Export Module Version 2.0
    Replies: 3
    Last Post: 9th April 2010, 01:47 AM
  3. "Script System" Type of Thing
    By MajorityCA in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 17th June 2009, 11:22 AM
  4. how I can use the VB .NET with .net script
    By FARAWAY_HELP in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 22nd May 2009, 04:22 AM
  5. Dot Net Script
    By danjo in forum Extension Development
    Replies: 44
    Last Post: 16th October 2008, 10:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •