• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] Interaction System

Status
Not open for further replies.
Level 6
Joined
Jun 8, 2008
Messages
256
Hello Hivers!

I'm trying to figure out how to make an interaction system, where you can either talk to, or interact with units and objects.

If you talk to a human there should be some response, and if you interact with an object there should be a response aswell, and in some cases you should receive an item or an something happens when either talking or interacting.

The thing is, I'm trying to figure out how this should work, do I need to do a separate trigger for every single human or object, or is there some other way to do this?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,207
Simply design a system via some form of table that takes an object type and returns a number which links to an array table representing which stats the object has. One of the stats is a function string which represents a function that will be executed to run the actions of that object. As there is no delay, just pass any objects and stuff via globals.
 
Level 6
Joined
Jul 25, 2005
Messages
221
JASS:
call ExecuteFunc("Reply")
He was talking in programming terms (right?), where you basically create a function that takes the object interacted and returns a number that represents the object type, process the return with a switch statement, eh, the equivalent of a switch statement being if then else, here's an example:
(Albeit a simple one)
I'd prefer using structs, but, meh... I'm too lazy

JASS:
globals
string array Names
endglobals

//The return function of the interacted unit
function UnitInteracted takes unit u returns integer
local integer interactedunit = 0
      if( GetUnitTypeId() == 'u000' ) then
         set interactedunit = 1
      endif
      if( GetUnitTypeId() == 'u001' ) then
         set interactedunit = 2
      endif
      if( GetUnitTypeId() == 'u002' ) then
         set interactedunit = 3
      endif
      if( GetUnitTypeId() == 'u003' ) then
         set interactedunit = 4
      endif
      if( GetUnitTypeId() == 'u004' ) then
         set interactedunit = 5
      endif
      if( GetUnitTypeId() == 'u005' ) then
         set interactedunit = 6
      endif
      if( GetUnitTypeId() == 'u006' ) then
         set interactedunit = 7
      endif      
      return interactedunit 
endfunction

function Bob takes nothing returns nothing
      call BJDebugMsg( "This is Bob, he likes pie" )
endfunction

function Larry takes nothing returns nothing
      call BJDebugMsg( "This is Larry, he hates pie" )
endfunction

function Lloyd takes nothing returns nothing
      call BJDebugMsg( "This is Lloyd, he's a girl" )
endfunction

function DrSuperGood takes nothing returns nothing
      call BJDebugMsg( "This is Dr Super Good, he likes girls" )
endfunction

function SuperHardTree takes nothing returns nothing
      call BJDebugMsg( "This is the Super Hard Tree, it's what I call my..." )
endfunction

function Foo takes nothing returns nothing
       call BJDebugMsg( "Foo" )
 endfunction

function Bar takes nothing returns nothing
       call BJDebugMsg( "Bar" )
 endfunction

//Some click event or something
function HandleInteractedObject takes nothing returns nothing
local string who_or_what_was_that
local integer UnitInformationTable
      set UnitInformationTable = UnitInteracted( GetTriggerUnit() )
      set who_or_what_was_that = Names[UnitInformationTable] 
      call ExecuteFunc( who_or_what_was_that )
endfunction

//Initiated at startup
function UnitTable takes nothing returns nothing
      set Names[1] = "Bob"
      set Names[2] = "Larry"
      set Names[3] = "Lloyd"
      set Names[4] = "DrSuperGood"
      set Names[5] = "SuperHardTree"
      set Names[6] = "Foo"
      set Names[7] = "Bar"
endfunction

 
Last edited:
Level 6
Joined
Jul 25, 2005
Messages
221
Oh, well, at least read the last link in the links tab, it's made by ralle, and it explains variables (GUI variables is generated globals)
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,207
My solution was designed to be the most efficent, and be capable of supporting 100s if not 1000s of different objects and actions. As it runs pretty directly (avoids unnescescary loops and usless comparisions), it would have a pretty constant execution time, meaning that you would be free to tigger as many objects and responses as you want (although 8192 would be the most object types the system would support without using multiple arrays).

Although ShadowMan's idea was kind of like what I was refering to, instead of multiple selection you should use some kind of hash table or gamecache so as to avoid unnescescary comparisions.
 
Level 6
Joined
Jul 25, 2005
Messages
221
Although ShadowMan's idea was kind of like what I was refering to, instead of multiple selection you should use some kind of hash table or gamecache so as to avoid unnescescary comparisions.
So each time you create a new object you just put it in the game cache and it can be returned through the function?

Yah, that would be the way to go, much like a database. But I don't see how you avoid the comparisons, how would you write a return function without them?

What is a hash table?

I've seen hash tables used in several programs (like DC++)
Is it like a database structure? because I know how that works, and it sounds like this method you're describing.

PM me if you don't want to continue this discussion in this thread.
 
Level 6
Joined
Jun 8, 2008
Messages
256
Well, I think this is what you ment DSG, but I've been thinking that I just put
Event - interact/talk spell used
Conditions - If target is A
Actions - Do actions that are ment for A

It just means I'll do a new trigger for every object, and I haven't tested if it'll work, but in my head I recall that it should.

Just one question, an array with 2 variables is no different then just 2 different variables?
Because then I can put all objects in an array and I won't have to scroll for miles when looking for some other variable.
 
Level 6
Joined
Jul 25, 2005
Messages
221
2 variables are two sets of memory bits randomly taken from current free memory in your computer, an array pieces all memory bits next to eachother, and makes it easier for the computer to get information from that memory bit when it is called.

Which is why you can use integers when you want a specific data member from your array.
It's an effective means of programming, it's structured, and saves time & memory!
The only problem with arrays that I can come to think of is allocation, if there isn't any room for it, you're screwed, but the same goes for a variable, albeit only one variable so it's a higher chance there is room for it, but an array needs memory that is connected.

Think of it like...

<----1----------2---------3--Your array-4---------5---------6----->
[arrayvar][arrayvar][arrayvar][arrayvar][arrayvar][arrayvar][memory chunk][memory chunk]

<-->----------------------------------------------------------<-->-----------------------------------------------------------------------------<-->
[var][memory chunk][memory chunk][memory chunk][var][memory chunk][memory chunk][memory chunk][memory chunk][var]

Array
0x01-0x06

Accessing: *ptr Address+arraynumber = 0x0(arraynumber)
Var
0x15, 0x40, 1x35, freespace x freespace
Accessing: *ptr address
 
Level 6
Joined
Jul 25, 2005
Messages
221
Yes.
But only if you have more than one piece of data you want to store, otherwise there is no point making a 1-sized array. :cute:
If you're using temporary data, you only need for the moment, don't use arrays. It's easier to find free space for one variable than for an array, and since it's only temporary it's better to use the quick option.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Using either a hash table or a game cache (which is a custom hash table, if I'm not wrong) won't remove any calculations, it will just make it so you don't see them, that's all.

If you stick your head in the sand, will no body see you?

As to what hash tables are - a hash table stores values for you in two parts: Key value, and Data value (not sure if those are the exact names).
The Data value is just your data, and the Key value is a value that supposedly points to the Data value.

Now if you give a hash table this, for example:
Code:
Add_to_hash("message","hello this is my message")

You can later on tell the hash table to return the value that "message" points to, and it will return "hello this is my message".

In a Like-Jass example:
JASS:
call Add_to_hash("message","hello this is my message")
call BJDebugMsg(Get_from_hash("message"))

This will, as I said, result in "hello this is my message" shown on your screen.
 
Level 6
Joined
Jul 25, 2005
Messages
221
Hm, much like
#define KEYWORD 0x00
cout<<KEYWORD

Isn't that more like macro..ing?
And in context with blizzs scripting, a lousy technique...
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Hm, much like
#define KEYWORD 0x00
cout<<KEYWORD

Isn't that more like macro..ing?
And in context with blizzs scripting, a lousy technique...

It's not a macro as it's in real time.

It's kinda nice when you deal with two values that have some relationship, a password and a name for example.
You can store your name as a key, your password as the data, then when the user enters them you check if the given password pointed by the given user name is right.
It's just another way of view, really.
 
Status
Not open for further replies.
Top