Author Topic: Event Script - VCE replacement  (Read 2629 times)

Event Script
Bringing Eventing closer to Scripting


Please note, everything and anything is very likely to change. I am open to suggestions.

Description
Event Script is my attempt to drastically increase the capabilities of eventers. VCE brought a whole new skill set to Blockland, however once you got too deep into it, things started breaking apart. Inspired by the usefulness of my Expression event (which I doubt anyone has heard of), I've decided to recreate VCE using a similar structure. Now you will not need 3 lines of events just to get a random number, or 50 lines to make a basic RPG tree with exp and levels, or an entire system to reserve chairs in a theater (that damn thing took hours!)

Planned Features
(In order of complexity)
 + Specialized events designed for members used to VCE's style.
    + Similar to ModVariable, IfVariable, etc

 + Multiple operations on one line.
    + (%var * 15) ^ 3.14 + 15 / $pi all on one line

 + Special tags used in centerprints, chat messages, etc similar to VCEs var replacers, but much more versatile.
    + Eg. <var:cl:name> as your used to
    + Including the ability to code within tags
       + Eg. <ct:print[(%var * 15) ^ 3.14 + 15 / $pi]> See Code Examples for more info

 + Inline variable operations, conditionals, and loops
    + Eg. for[%i = 0, %i < 10, %i++] { %i % 2 == 0 ? { print["You are a friend"] } : { print["You suck"] }}

 + Variable classes (Torquescript doesn't even have this!)
    + Numbers stay as numbers, vectors, arrays, strings, and easy to convert between them.

 + Much closer to real scripting. Learn to script while eventing. Its how I and many others started.

 + Ability to call multiple events on a single line. No compatibility issues.
    + Note that this may have security flaws. I am still currently looking into a secure method.
    + Eg. $self.setColor[ getRandom[0, 63] ] would call the setColor event on the brick calling the event.
    + Allows for any event to be called, including other add-ons. No issues with parameters not taking variable replacers.

 + Triggered functions, no more VCE relay loops!
    + Method to remove the need of relay loops to check when a player does something.
    + Still working out the details on this one.
    + Will probably be something like onPlayerJump, or onPlayerJet. Less abusable than you would think.


Code Examples

onActivate > EventScript > Eval > %client = $client !%client.gender.isset ? { %client.gender = getRandom[0, 1] }
onActivate > Client > CenterPrint > You are a <ct:%client.gender == 1 ? {print["Boy"]} : {print["Girl"]}>.

Technical explanation:
%client = $client
     %client is a local variable stored for the duration of the eval. $client is a global variable that is set to the client that is triggering the event.

!%client.gender.isset
     Checking if the gender variable is not set (The ! inverts the Boolean)

? { ... } : { ... }
     If the previous statement is true, execute the code within the { }, otherwise execute the code in the { } after the colon.

%client.gender = getRandom[0, 1]
     Set the variable 'gender' on the client to be a random integer between (and including) 0 and 1. This variable will be kept on the client and can be accessed in other scripts.

print["Boy"]
     Replaces the code tag with the contents of the string. Does nothing outside of a codetag. Similar to how VCE variable replacers work.


Variable Info
Classes:
  Numbers (Integers and floats)
    Eg. %number = 4
  Strings (Letters, words, sentences, that sort of thing)
    Eg. %string = "Hello world!"
  Booleans (True or false)
    Eg/ %bool = $client.hasPlayer
  Vectors (infinite dimensions)
    Eg. %vector = [5, 2, 10]
    Technically just an array of numbers.
  Objects (Clients, players, other bricks, vehicles, bots...)
    Eg. %player = $player, %brick = $self
  Arrays (of each other type, number arrays, vector arrays, etc)
    Eg. %friends = ["Boodals", "Jam Jar", "Blobo", "Elm", "Cant think of friends", "etc", 5.251, ["and even", "multidimensional", "arrays!"] ]

Types:
  Local variables are variables that are deleted when the code is finished executing.
    Eg. %local = 3.14
  Global variables are read only, used to get info from Blockland into Event Script.
    Eg. $player, gets the player who activated the brick (if there is one)

Privacy:
  Variables will be able to be set as public or several cases of private.

  Private variables will be able to be read by other users, but only modified by your bricks.
  Trusted variables will be available to be modified by people with your full trust. This may change depending on a few things.
  Whitelist variables will be modifiable by people with certain IDs. Probably will use syntax like private[3504, other, IDs, here] %var
  Public variables will be available to be modified by anyone.


Suggestions welcome!
I need to know what you guys want to see. I am especially interested in how I can make this more user friendly, as i'm sure this topic alone has scared many uses off. VCE itself was hard to get into if you didn't know where to start. Id like to be able to give this to anyone and have them be able to use it within a couple hours max (obviously not to its full capability, but you get the idea).


Help?
I think I could pull this off on my own, however it would take much longer than I have before life gets in the way (uni, exams, etc). If you think you can help me, send me a PM or post here, and we can meet up and chat.
« Last Edit: February 26, 2014, 09:09:23 PM by boodals 2 »

Topic Changelog
Most recent first.

Added info about variable privacy. (Variable Info)
Added possibility of Triggered Functions. (Planned Features)
« Last Edit: February 26, 2014, 09:08:37 PM by boodals 2 »

i really like that true/false colon idea a lot.
have you considered anything regarding varlinks in VCE?

Var links were buggy and in general a bad idea (imo). Unless I can find a new way to do them, I doubt I will have any functionality for them.

Why did you use them? I might be able to create a new, better system.

i used them when i was trying to make an RPG where anything related to using resources would display varlinks, like smithing, to select what to make. sort of like runescape classic if you have ever seen that before.
while in the middle of this i found out how buggy and annoyingly sluggish varlinks were and just stopped lol

Well, if you can think of a way that I could implement them, ill see what I can do.

Btw, I've updated the topic with Triggered Functions and Variable Privacy (two planned features i forgot about).

Ill use the reserved post to show updates to the topic i guess..

onActivate > EventScript > Eval > %client = $client !%client.gender.isset ? { %client.gender = getRandom[0, 1] }
> Eval >
Eval
I've just lost all hope in this mod. Letting the client use eval is one of the worst ideas I've ever heard.

I've just lost all hope in this mod. Letting the client use eval is a terrible idea.

Implying that there is only one meaning to the word Eval.

Eval = evaluate. It reads and executes the code. Although maybe I should have used exec instead of eval.. No screw that. Eval is the correct term.

What he means is you cannot do these "event scripts" directly through torquescript eval.

If you do that then there is no hope for you. At all. Might as well just trash it now if you can't think of another way.

What he means is you cannot do these "event scripts" directly through torquescript eval.

If you do that then there is no hope for you. At all. Might as well just trash it now if you can't think of another way.

Of course. I'm not gonna expect to just pass this into torquescript and have all the work done for me. Where would be the fun in that?

Well, if you can think of a way that I could implement them, ill see what I can do.
Maybe instead of VarLinks you could implement some sort of GUI that would pop up. That's the only other way I can think of doing it.

Also looking forward to this very much.

In case you're interested, I implemented something similar to this not too long ago (not with quite as many features though).
For example:

onActivate -> Self -> expr -> (n++ % 4) == 0
onActivate -> Client -> CenterPrint -> Click counter: <v:b:n>
onExprTrue -> Self -> playSound -> Synth_04.wav
onExprFalse -> Self -> playSound -> Synth_00.wav


The most recent version worked by a tokenizer which parsed the expression and yielded a list of syntax elements found (numbers, operators, identifiers, etc.), then constructed a 100% safe TorqueScript expression and evaluated it. I was planning to replace this with an actual runtime but I got lazy ;).

I'll send it your way if you want.

-Snip-

Id be very curious to read your code, to see if I could make mine any better, however ill most likely be starting from scratch. The expression event that I mentioned briefly in OP did something similar to what yours does, except it worked with VCE. If anyone's interested, its hidden under AdvVCE in this topic. You can download it there too, although it is much older than the version i use now.