Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Pages: 1 2 [All]

Author Topic: New to WME scripting  (Read 13323 times)

0 Members and 1 Guest are viewing this topic.

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
New to WME scripting
« on: January 31, 2013, 07:51:13 PM »

Hello all, I have just started re-learn WME, I have completed the tut and now I'm getting my head round it by designing a little 2 level micro game. I'm really impressed with WME and the language reminds me of AS2.

Now i'm getting the stages of scripting and inventory bits - so I thought I would ask the veterans.

for argument sake, if i wanted a "?" to hover over all interactive objects and then you "look at (interact)" and the object becomes discovered (named) so "?" changes to "object name (fork)"
how complicated would that be to manipulate in the code?

Last one in terms of object orientated programming and changing frames. Is it straight forward for to make and object change its state by repeated actions (frame 1 frame 2) or the "if condition" of something on a stage? example: character kicks wall, crack appears, kicks again crack widens, again wider and so on and so on?

Thanks for any help on this.

Regards, ::wave
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

ciberspace

  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 116
    • View Profile
    • Tele Juego
Re: New to WME scripting
« Reply #1 on: February 01, 2013, 03:11:43 PM »

Scripts - you can assign one or more script to a sprite; that way you can programmatically control sprite properties, frames and the animation flow

Quote
Sprite object
The Sprite object allows you to access the properties of your animations. Sprite objects can be queried using the GetSpriteObject methods of various objects and their equivalents.



Methods
Actions 
GetFrame Returns one animation frame.
AddFrame Adds a new frame to the animation.
InsertFrame Inserts a new frame to the animation.
DeleteFrame Removes specified animation frame.
Reset Resets the animation.
Pause Pauses the animation.
Play Resumes a paused animation.
Script functions 
AttachScript Executes a script file and attaches it to the object.
DetachScript Terminates a specified script file and detaches it from an object.
IsScriptRunning Queries whether a specified script file is running and attached to an object.
CanHandleMethod Queries whether the object supports a method of a specified name.
::wave

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: New to WME scripting
« Reply #2 on: February 03, 2013, 11:38:30 AM »

Hello, Thanks :-) Which one of those methods would resemble an action> next frame of sprite animation or sub frame?. like a button click.

Cheers,  ;D

P.S is is straight forward to see how many scripts you have attached to an object/sprite?
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

Jose

  • Regular poster
  • ***
  • Karma: 2
  • Offline Offline
  • Posts: 134
    • View Profile
Re: New to WME scripting
« Reply #3 on: February 13, 2013, 03:21:05 PM »

Hi jimm84,

I think both of your questions can be easily achieve using custom properties on the entities. For example you can have one custom property called 'viewed' so while this property is 'false', the caption of the entity will be '?' then when the player look at or interacts with the entity you can change the property to 'true' so from that moment on, the caption of the entity will be 'fork'. The crack on the wall could be handled in a similar way changing the sprite based on the value of a custom property called, for example, 'crack_state'. Also you can raise events from any frame on a sprite that can be handle in the scripts.
Logged

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: New to WME scripting
« Reply #4 on: February 18, 2013, 11:28:32 PM »

Thanks Jose, that makes sense. like a said it reminds me of actionscript for flash. :-)
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: New to WME scripting
« Reply #5 on: March 01, 2013, 10:40:18 PM »

Hello all, I'm starting to get my teeth sunk into the scripting stages and was wandering if someone could point me in the right direction, I know ... I'm new! :-) Here goes.

I have a boulder sprite animation that crashes down from a ceiling. The animation plays the moment the screen loads, I would like the animation to freeze on the on the first frame of the animation until ... the boulder is triggered. I keep making references to as2 but it's not.

So...

Animation is paused - then triggered (left click, keep it simple) - and then the animation stays on the ground (last frame)
Thanks for your help. Would I be able to find snippets of code in the resource that could show me how to do simple interactive animation like this? I find it easier to learn by reverse engineering things, ok, breaking things!

Thanks for your help and support! :-)
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

appaul

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 10
    • View Profile
Re: New to WME scripting
« Reply #6 on: March 02, 2013, 08:13:23 AM »

If you go to sprite editor, and go to frame properties on Frame 1, there's a field called "Event".
Fill that in with, say, "FirstFrame" and then go to Sprite properties and attach a scipt that has:
Code: [Select]
on "FirstFrame"
{
  this.Pause;
}

Then go to your Entity that contains the sprite in scene manager, make sure it's interactive and attach this:
Code: [Select]
on "LeftClick"
{
  var boulder = this.GetSpriteObject();

  boulder.Play;
}

I haven't tried it, but I think that should work.
As for freezing on the last frame, just make sure "Looping" on the sprite is unchecked. Or do a similar thing as the first step above.
Logged

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: New to WME scripting
« Reply #7 on: March 04, 2013, 02:18:14 PM »

Thanks a Appaul, I will have a go at applying this over the next few days.

I was wandering with the "firstframe" is labeling the event/function, or are your labeling the object for other pieces of script to reference to? .. if that makes sense.

Regards,  :)
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

appaul

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 10
    • View Profile
Re: New to WME scripting
« Reply #8 on: March 05, 2013, 01:07:05 AM »

No problem.

You're not really labeling anything. You're creating an "event" on that specific frame, so that when the sprite reaches that frame, the engine looks for the name of the event in the attached scripts and executes that block of code.
http://docs.dead-code.org/wme/scripting_about_events.html
Logged

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: New to WME scripting
« Reply #9 on: March 06, 2013, 12:43:34 PM »

Cheers for that! I'm being a nightmare, I had a go at using your script yesterday and I could not get the animation to stop. After a while I even tried "this.Pause;" when the object is left clicked / taken to try and stop a looping animation. This was attached to the object in the scene. 

When I was trying the script no errors were returned... it just did'nt work. Bit stumped, any clues?

Cheers,
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

appaul

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 10
    • View Profile
Re: New to WME scripting
« Reply #10 on: March 06, 2013, 07:31:52 PM »

Sorry, that was actually my bad. I work mostly with 3d actors, so a couple of things slipped past me.

First off, they should be .Play() and .Pause() - with the brackets.

Second, after a couple of tests, it seems like the frame event calls the script attached to the entity and not the sprite. So instead of attaching a script to your sprite, just add the "FirstFrame" event to the entity script, so it looks something like this.
Code: [Select]
var boulder = this.GetSpriteObject();

on "FirstFrame"
{
 boulder.Pause();
}

on "LeftClick"
{
 boulder.Play();
}
Logged

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: New to WME scripting
« Reply #11 on: March 07, 2013, 01:59:17 PM »

Hello again, no worries. I had a tinker yesterday with getting an animation to start and stop which worked well when clicked... but not quite how I needed. :) I will have another look over the next few days, I'm working with flat 2d sprites.

I was wandering with the Play(); etc what can be placed in the brackets? frame number?

When you say entity, do you mean in the scene editor?

Thanks for the snippet.
 :)
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

appaul

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 10
    • View Profile
Re: New to WME scripting
« Reply #12 on: March 07, 2013, 07:35:16 PM »

I was wandering with the Play(); etc what can be placed in the brackets? frame number?
Nothing. I believe that's just the format for functions and methods.

When you say entity, do you mean in the scene editor?
Yes. You attach the script to the entity in your scene that's using the animation.
http://docs.dead-code.org/wme/inside_entites.html
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: New to WME scripting
« Reply #13 on: March 07, 2013, 08:37:09 PM »

Most programming languages I have worked with use this format of calling functions and methods. That is, all functions need () when they are called. So, a function that takes two arguments is called:

Code: WME Script
  1. function1(argument1, argument2);

while a function that takes no arguments is called:

Code: WME Script
  1. function2();

In WME, if you call an object like this:

Code: WME Script
  1. object.function();

it means you want to call the function named "function" inside that object, that takes no arguments. On the other hand, if you do this:

Code: WME Script
  1. object.Something;

then you are referring to the object attribute named "Something".
Logged

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: New to WME scripting
« Reply #14 on: March 10, 2013, 07:38:53 PM »

Thank you both, I'm becoming a bit more familiar with it now! So exciting. I've made a boulder play when clicked... and freeze when finished. The boulder becomes an island basically, but now... how do I get the scene to remember that the boulder has been interacted with?

When the character leaves the room and comes back everything returns to its original state?

Thanks all, :D
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

ciberspace

  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 116
    • View Profile
    • Tele Juego
Re: New to WME scripting
« Reply #15 on: March 11, 2013, 03:05:52 PM »

in scene_init.script

Code: WME Script
  1. if(!State*******.Visited)
  2. {
  3.   State*******.Visited = true;
  4.  
  5.   // this is our first visit in this scene...
  6.  
  7. }
  8.  

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: New to WME scripting
« Reply #16 on: March 12, 2013, 11:57:57 PM »

Hello, thank you you Ciberspace. That tells me where - So how would I place my "interacted with" code in there? would  it need to say...

if boulder fell, then stay fallen on last animated frame of sprite - if not then stay as original.

and if condition of sorts.

Regards, :)
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: New to WME scripting
« Reply #17 on: March 13, 2013, 07:09:54 PM »

You would need to use your own scene variable, similarly to "Visited". I will use the default scene_init.script as a template to

Code: WME Script
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // scene state
  3. global StateScene1;
  4.  
  5.  
  6. // default values
  7. if(StateScene1==null)
  8. {
  9.   StateScene1.Visited = false;
  10.   StateScene1.BoulderFell = false;
  11.   // add scene states here
  12. }
  13.  
  14.  
  15.  
  16. ////////////////////////////////////////////////////////////////////////////////
  17. // setup scene according to state variables
  18. if(StateScene1.BoulderFell)
  19. {
  20.    //set sprite frame to last
  21. }
  22.  
  23. ////////////////////////////////////////////////////////////////////////////////
  24. if(!StateScene1.Visited)
  25. {
  26.   StateScene1.Visited = true;
  27.  
  28.   // this is our first visit in this scene...
  29. }
  30.  

So you have a global variable StateScene1 which will contain the variables that describe the scene state. When you first visit the scene the variable is null, therefore the initialization code inside the first "if" is executed. Then, when the boulder falls, you must assign true to StateScene1.BoulderFell.

This way, next time you visit the scene, the variable will still be true, therefore the code of the second "if" will be executed, setting the sprite to the last frame.

There are other ways to achieve what you want (which I have tried and made my life complicated  ::)) but I believe the way I described above is the best to handle the scene state.
Logged

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: New to WME scripting
« Reply #18 on: April 02, 2013, 11:08:09 PM »

Thank you

Excellent! I will have to put that into practice! it seams to make sense to me, thanks.

Another question.
I was wandering how to go about making an item from your in work with scene object?

Example, select stone > throw stone at wall (plays animation), wall caves in, object vanishes from inventory.
You can then move into a new walkable area?

;-) any pointers?
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: New to WME scripting
« Reply #19 on: April 07, 2013, 08:54:42 PM »

Hello, I have been having a crack with setting up the if condition in the start of the Scene_init, think it will take quite a bit of getting my head round as I was getting a scene script error .... sigh... With my boulder I have used a 'play' and 'pause' function with my boulder anim do how do you make a sprite anim jump to certain frame? sorry, i'm new to WME

Thanks,
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/

dongo

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 29
    • View Profile
Re: New to WME scripting
« Reply #20 on: April 08, 2013, 03:41:54 PM »

hello i am spannish, but i am try to help you, you have the atribbutte CurrentFrame of the objet sprite ( sprite_var.CurrentFrame), with this attribute, you can Specifies the index of the currently playing animation frame.
Logged

jimm84

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
    • JD Portfolio
Re: New to WME scripting
« Reply #21 on: April 09, 2013, 10:49:42 PM »

Thanks
Logged
Hello! :-) Illustration & Animation Portfolio http://jdillustration.jimmsdesign.co.uk/
Pages: 1 2 [All]
 

Page created in 0.079 seconds with 21 queries.