Jump to content

Josh

Staff
  • Posts

    23,223
  • Joined

  • Last visited

Posts posted by Josh

  1. Make sure "Show Helpers" is enabled so you can see links. If you don't see a link where you think you should, try changing the link index in the main menu. This sets the link index that is displayed, and if you create a link it is created on this index.

  2. I'm going to do some experiments with a single lua state. It will make scripting harder, and you will have to manually clean everything up yourself, but it would allow shared data like this:

     

    player.enemy.bullet:shoot()

  3. You're planning to write a unique script to make all those events occur? I think it makes more sense to have a set of rules so the artist can place objects and adjust settings without writing a new script for each map.

  4. That example is just a lot of different things going on, but nothing itself is very complicated:

     

    Trigger sets a key in the player model:

    SetKey("controlmode","auto")

     

    Trigger sets the camera model's target to the player. The camera script follows the target, when one exists.

     

    Trigger sends a message to a sound entity to play the music.

     

    Player moves to his target until he reaches it, and some more events are triggered.

     

    ...and so on.

     

     

    A bullet hitting a player, hurting them, and updating the owner's score was about the most complicated single interaction I could think of. Any other ideas? One advantage of this system is it encourages you to create a defined set of actions with the messages, instead of making spaghetti code.

     

    One disadvantage is when you have something like the roads, and you want to tell if a wheel of a car lies on the road. You need to communicate with the road script, but how do you get that info back? That is where it gets sticky.

  5. Maybe enter this text in the property editor:

    function CustomBehavior(entity)
    Notify("Hello!")
    end

     

    Then in SetKey add this:

    function SetKey(key,value)
    if key=="customscript" then
    	dostring(value)
    end
    end

     

    So now at this point the new code has been evaluated and the function is usable in Lua.

     

    Now add this to the message receive function:

    function ReceiveMessage(message,extra)
    if message=="custombehavior" then
    	CustomBehavior(entity)
    end
    end

     

    I don't know if this is a great idea, because it is confusing, and the state is shared across all instances of the model, but it's interesting that it works.

  6. I think at some point you should just work within the bounds of what you have. Eventually you will have more options to do stuff like this, and writing workarounds in the meantime will likely cause unforeseen problems like what Red Oktober mentioned. You'll walk up the stairs and find a lot of fish flopping around in your living room, or something.

  7. I want to make sure the system can handle complicated interactions. Here is an example where a bullet shoots an enemy. I added an imaginary extra "sender" parameter to make it easier:

     

    Bullet/player script:
    enemy:SendMessage("hurt",0,"-5")
    
    Enemy script:
    function ReceiveMessage( message, extra, sender )
    if message="hurt"
    	self.health=self.health-tonumber(extra)
    	if self.health<=0 then
    		self:Kill()
    		sender:SendMessage("addscore")--Add to the killer's fragcount
    	else
    		self.model:EmitSound(sound_ouch)
    	end
    end
    end

    What other scenarios can you think of that might be difficult? As far as I can tell, this system can handle everything, but I want to make sure.

  8. It would hurt something, because it would cause more bugs for me to spend time on. The biggest problem would be if two models have the same name, and then one is freed, there would be no model for that name, even though it exists.

     

    You can have up to 8 targets. I can raise that if needed, but it seemed like enough for now.

     

    You can loop through all entities with the world entity list:

     

    for entity in iterate(CurrentWorld().entities) do

    end

     

    Or:

     

    for entity in iterate(CurrentWorld().models) do

    end

     

    Or:

     

    for entity in iterate(model.reference.instances) do

    end

  9. You can even write a little script in the property editor and make the model execute that code. There's an option in the text property to open a multiline text editor in a separate window. I didn't use this feature, but it is an example of just how flexible Lua is.

  10. The point of targets is so you don't have to type in unique names and find them later. Just click and drag between two models. Unique names are more error-prone. Target relationships won't run into problems with redundant names. You can set up one system of objects, then copy and paste them, and the copied group will behave the same, with targets intact. If you copy and paste named objects, their names will be identical, and they will interfere with each other.

×
×
  • Create New...