A Community discussion forum for Halo Custom Edition, Halo 2 Vista, Portal and Halo Machinima

Home  Search Register  Login Member ListRecent Posts
  
 
»Forums Index »Halo Custom Edition (Bungie/Gearbox) »Halo CE General Discussion »Globals: Scripting help please.

Author Topic: Globals: Scripting help please. (30 messages, Page 1 of 1)
Moderators: Dennis

grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 14, 2012 10:39 AM    Msg. 1 of 30       
So i know some scripting, what i don't know is what i need to. I don't know how to use globals, and i don't know how to make ui_widgets. I was wondering if someone, anyone, everyone, whatever, could post some scripts containing ui_widgets and globals and tell me how they work. I asked Kirby, but he's a busy dude, and i understand that (and i constantly ask him about anything script related, i think i might be getting annoying. Lol) Anyway, I've watched countless tutorials, Kirby's new one, looked at globals in scripts, ect ect. And still don't understand it. So any help will be greatly appreciated. Thanks, guys.


kirby_422
Joined: Jan 22, 2006

Apparently public enemy number 1?


Posted: Sep 14, 2012 11:13 AM    Msg. 2 of 30       
If I don't answer your PMs right away, and go to bed for the night, you'll make a thread on it?... I find that a bit overkill *shrug*

Globals, they are just variables.
(global <data type> <name> <initial value>)
eg, (global short my_number 1234)
(global unit player0 (unit (list_get (players) 0)))
you can later (set my_name 4321) and anytime you use it, it will be 4321 now. You use it by placing it somewhere where that data type is accepted, so with a short, its basically anywhere. Mathematical equations, list_get <object_list> <short>, unit_set_current_vitality <unit> <short> <short>, etc.
They are used, because what if you want to use the same script, but sometimes you want 1234 to be used, and sometimes 4321. They can also be used for inter-script communications.
(global boolean my_bool false)
(script startup a
(sleep_until my_bool 15)
(sv_say "success")
)
(script startup b
(sleep 600)
(set my_bool (not my_bool))
)
With something like a unit, or an object, you get a hook onto the direct object. With a player, you get a reliable way of tracking players, since you grab random player objects out of the object_list normally. If you want to make sure that you are getting the same player over and over again, you would want a global of that player.

So, say you have
(global unit p0 none)
(script startup setup
(sleep 90)
(set p0 (unit (list_get (players) 0)))
(sleep_until (> player_spawn_count 1) 60) ;;Wait for more than 1 player in the server
(if (= p0 (unit (list_get (players) 0))) (sv_say "player0 is still 0 in the object_list") (sv_say "player0 is no longer 0 in the object_list"))
(sleep_until (!= (list_count (players)) player_spawn_count) 10) ;;wait till someone dies.
(if (= p0 (unit (list_get (players) 0))) (sv_say "player0 is 0 in the object_list") (sv_say "player0 is no longer 0 in the object_list"))
) ;;This script doesnt take into account them dying before the first check, but whatever.


Globals are good for scripts that vary from time to time (even if the varying is only debugging), communicating between scripts, and keeping tabs on certain objects.
(set <global name> <new value>)
(inspect <global name>) ;; dev mode, read the variable contents


What about widgets do you want to understand? running a script from a widget is as simple as clicking the script flag, and typing the dormant script name in the 'script' text box.
For this picture, the dormant script it runs is powerbutton
When a dormant script is called from a ui widget, it is able to run over and over again. When you use wake, you can only use it once.


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 14, 2012 12:10 PM    Msg. 3 of 30       
Well, not right away. i made the thread because i'm slow on picking up on this kind of thing, and i figured that other people could help explain it better too. Okay, so i made a new ui_widget_definition in korman00 V2 and i'm not seeing the flag that says "run sapien script" I'm assuming it's the unmarked box under "go back to previous widget" but i'm not sure. Lol. So, i make my widget, put in the script name, under "script", and it automatically links it to that? i don't have to write anything in the script? Put in the location of the script? Put in the location of the widget in the script with some fancy commands after it? nothing at all?

Secondly (global <data type>;;unit, short, long, anything? <name>;;of the global, so you can call it with a script <initial value>);; number? true or false? 0 is false 1 is true? what if i set it to 5? Like this

(global boolean my_bool false)
(script startup a
(sleep_until my_bool 15)
(sv_say "success")
)
(script startup b
(sleep 600)
(set my_bool (not my_bool))
)
how would it go from false, to 15? what does the 15 resemble? And what does it mean when it says "not my_bool"? does this set it to false?

Third
(global unit p0 none) ;;Sets it so p0 = nothing
(script startup setup
(sleep 90) ;;wait 90 game ticks, 3 seconds
(set p0 (unit (list_get (players) 0))) ;;sets p0 to = player0
(sleep_until (> player_spawn_count 1) 60) ;;question, what does the "is less then" symbol do here?
(if (= p0 (unit (list_get (players) 0))) (sv_say "player0 is still 0 in the object_list") (sv_say "player0 is no longer 0 in the object_list")) ;;Hmmm. not sure about how this one works. Just looking at it it looks like it would check to make sure p0 is player0 and then sv_say he is, but also say that he isn't...Lol?
(sleep_until (!= (list_count (players)) player_spawn_count) 10) ;;i do not understand what the "!" is for, or what it equals, but it checks the list of spawned players every 10 ticks?
(if (= p0 (unit (list_get (players) 0))) (sv_say "player0 is 0 in the object_list") (sv_say "player0 is no longer 0 in the object_list")) ;;again. Lol.
)


kirby_422
Joined: Jan 22, 2006

Apparently public enemy number 1?


Posted: Sep 14, 2012 12:27 PM    Msg. 4 of 30       
I believe in kornman00v2 the checkbox you want is nameless, but yes. that box controls whether it executes the script or not. And you just place the name of the dormant script (same name you would use to wake it) in that script textbox.

if you wrote myrandomscript, in that box. your dormant would be (script dormant myrandomscript
;;<blah>
)

you're mistaking how sleep_until works.
(sleep_until <boolean> [<short>])
pauses execution of this script until the specified condition is true, checking once per second unless a different number of ticks is specified.

the number afterwards isnt the condition, its how often to check. The first part always checks for true (any non-zero number, or the direct true and false words)
for the data type, yes, it can be anything object_definition, string, short, long, real, ai, object, object_name, unit, unit_name, vehicle, vehicle_name, scenery, scenery_name, device, device_name, sound, object_list, etc. You can even hold script's in a global (although ive never tried it, its considered valid. Open a scenario, go to the global section. look at that giant list of options)

The name is how you referance it. You need something valid for the data type, so you cant say you're giving it a vehicle, then giving it 1234, unless you have a vehicle named 1234.

(not <boolean>)
returns the opposite of the expression.

Really, I could of just written true in that slot, since thats what I want it to do. Anyways, it will see that my_bool is false, so it will return the opposite of that; true. setting a global boolean to (not itself) will toggle it. If it was true before, it will become false. if it was false before, it will become true.

player_spawn_count is a global built into the game, that shows the number of players in the sever. (> player_spawn_count 1) is the same as 'player_spawn_count > 1'. Its waiting until the player count is more than 1 (that another person joined the server.

If the player stored in the global, is equal to what is returned by (unit (list_get (players) 0)), then it will state that they are still the same. If the object_list instead made the previous player0 into player1, it will tell you that the object_list has changed this.
(!= <expression> <expression>)
returns true if two expressions are not equal

If the number of living players (Counting the items in the object_list), is not equal to the number of players in the server (player_spawn_count). that's what im checking.


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 14, 2012 01:40 PM    Msg. 5 of 30       
Okay, so now i'm learning a little bit. Thank you. Um, i tried clicking that unmarked box, and it won't check. For some reason it's unselectable. I also tried making the ui_widget_definition adding an event handler, and then selecting the box in normal guirilla, and all of the boxes are unusable there. Any ideas?


kirby_422
Joined: Jan 22, 2006

Apparently public enemy number 1?


Posted: Sep 14, 2012 01:45 PM    Msg. 6 of 30       
www.modacity.net/forums/showthread.php?24748-Custom-UI-Troubles higuy checks it outside of guerilla. You could always do it too *shrug*


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 14, 2012 02:41 PM    Msg. 7 of 30       
Well, since that didn't explain how he exported it i just re-installed OS hek without the OS features on the game. Lol. I am wondering though, what guerilla are you using in the image? Because it doesn't look like stock guerilla, or either of the kornman versions, or even OS. Lol. Oh, will the widget have the same name as the dormant script? i mean, in-game when you see it, if i name my script "button" will the widget say "button"?



Edit: okay so i just tried it. Something simple
(script dormant button
(sv_say "hello")
) and made a new ui_widget_definition and put "button" in the "script" textbox. But in game, nothing. I'm using the same settings you did in that image, it's a multiplayer map, i checked in every section. Nothing. At all...Any ideas?
Edited by grunt_eater on Sep 14, 2012 at 03:07 PM


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 14, 2012 08:42 PM    Msg. 8 of 30       
Yeah, i noticed this while copying down some things from the red team change button. Still one problem. I have it set up completely. The only thing i don't have is a Unicode string list. Besides that, i have everything in place. But in-game it still doesn't show up :/


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 14, 2012 10:50 PM    Msg. 9 of 30       
-_- i asked what i needed to do to add a ui widget...i wasn't told this step. Lol. thank you. My widget is invisible until selected, lol. I'll see what i can do to figure out a fix for this. Now all i've gotta do is that and i'll have my own UI widgets, yay. lol. And i can start scripting what i need. Now i just need to fully understand globals o_o lol.


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 16, 2012 09:37 AM    Msg. 10 of 30       
Quote: 1283023's long post


Thank you for that definition. Kirby was helping, he taught me everything i know about scripting, but when you said variables in other scripting\coding languages, i thought back to when i learned a little java script. I instantly got it. Though i'm not sure how to do what i want with them...Hmmmm. I want to learn, so i don't just want someone to hand me the answer. But what i'm going for is this.


I want to use the default color change widgets to detect the color of the local players biped. This will be for Multiplayer. Kirby suggested doing it with a custom UI but i wanted it for the map itself so everyone wouldn't have to have the custom UI. So what i'm looking for is, when you open the map, it asks you to choose your color. It then saves this as the local players color. I'm not sure how to do this. But i need it for two different features in this map. And it would have to be set up so that the global saves which player chose which color. SO the global would have to define the local player as, say, p1. And then say that if color was 1, it would be white, if it was 2, it would be black. And so one down the list. i have no idea how to do this. So lets start with this.
(global short p1color 0)
(script dormant white
(set "p1color" 1)
)
(script dormant black
(set "p1color" 2)
)
(script static void test
(if (= "p1color" 1)
(begin
(sv_say "player one's color is white")))
(if (= "p1color" 2)
(begin
(sv_say "player one's color is black")))
)
(script continuous here-we-go
(sleep_until (unit_get_current_flashlight_state (unit (list_get (players) 0)) 1)
(test))
)
Now i just hook up the color change widgets to the dormant scripts, and make one for each color. And all i need to do is be able to figure out which biped is the local player...The hard part :/ lol.
Edited by grunt_eater on Sep 16, 2012 at 09:39 AM
Edited by grunt_eater on Sep 16, 2012 at 09:40 AM


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 16, 2012 02:50 PM    Msg. 11 of 30       
Can't use open sauce, don't know what rcon is. Lol. And the change team widgets are server side, and i believe the color change are, because the game has to display your color correctly to the entire rest of the server or their own PC's. I just need a way to make it so that it detects local player, and detects what color they are. And since i can't host a dedicated server with a custom map, i can't test the script Kirby gave. Hmmmm. What to do, what to do...


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 16, 2012 03:16 PM    Msg. 12 of 30       
Understood. But if the widget activates a dormant script, would the script sync? also, could the "(unit_set_permutation <unit> <string> <string>)" be used to set color permutations? Lol.


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 16, 2012 04:24 PM    Msg. 13 of 30       
Okay, all i'm seeing is password things. Not how to execute a command with rcon. lol. Yes, i'm a noob. That's why i ask questions, to learn. Lol.


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 16, 2012 05:01 PM    Msg. 14 of 30       
No, i read it, i just didn't understand it 'till now. So first establish an rcon password, say, entrance1. Then i can pass commands by typing "(rcon "entrance1" (wake [script-name]) and it'll sync to all connected PC's, correct?


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 16, 2012 06:12 PM    Msg. 15 of 30       
Got it. But if a client executed it then the vehicle wouldn't actually be spawned, because it would only exist on their computer, right?


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 16, 2012 06:51 PM    Msg. 16 of 30       
And you have the patience of a dying man :) I swear, people nowadays. Your inpatient and expect everyone to already know everything you do. Lol. How about instead of ridiculing someone who doesn't understand, you teach them. As far as i knew so far, (object_create anew) commands didn't sync unless executed by the host. Just like (cheat_all_vehicles). So since no one had ever told me otherwise, that's what my understanding was. So, since the script command would be executed on a client PC, i didn't think it would sync. My bad, i'm sorry for not knowing how the halo world goes 'round by default. Lol. Now i know different. I'm not incapable of learning, you're just a bad teacher ;)


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 16, 2012 07:16 PM    Msg. 17 of 30       
That's where you're mistaken. I've read every one of your posts. You just don't make it clear what you're trying to say, friend. You need to remember that you're using terms and techniques, that i haven't heard of, so try giving an explanation of what you're saying and how it works. Unlike you, i haven't been programmed my whole life to just take what someone says. I need to understand it, otherwise there's no point in me learning it. I prefer to use my mind, instead of just copy\pasting what other people do and say. So thanks for the help you've given, but for future record, try making yourself more clear. K thanks.
Edited by grunt_eater on Sep 16, 2012 at 07:18 PM


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 16, 2012 07:33 PM    Msg. 18 of 30       
All except rcon, I've understood for the past few months. Now, today, i understand rcon. But I've never used, or even heard of, these techniques. So, no, it still hasn't sunk in what you're talking about up till now. As i said, you could try explaining what it would do, instead of just posting it and expecting everyone to understand you. And just because i'm new at this and trying to learn, doesn't mean you have to be a dick about it, acting all high and mighty. I asked to learn. Not be treated like your dog. But instead of teaching, you just post things with a brief explanation of how they work, and don't ever get into the details of how or the outcome, and expect me to already know. If you don't have the time or patience to help someone understand, then what the hell are you doing on this thread?
Edited by grunt_eater on Sep 16, 2012 at 07:36 PM
Edited by grunt_eater on Sep 16, 2012 at 07:39 PM


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 16, 2012 07:50 PM    Msg. 19 of 30       
Pretty much everyone here learned everything they know by themselves. I mean, Kirby taught me the basics of scripting, helped me in the spots where i was stuck. But for the most part, I've figured out everything i know by myself. And i have been asking miner questions. "if a client executed it then the vehicle wouldn't actually be spawned, because it would only exist on their computer, right?" That's a question. And instead of answering, you just lazily gave up. No, i'm not a bad student, i read, and re-read your posts. And then i ask questions. But instead of a strait forward answer, you act like i should already know, and like you've explained it several times, when you haven't. No, i'm not a bad student, when something isn't clear, i ask a question to give me a better understanding. When teaching, you're not clear, and then ridicule me for asking question. If you were a school teacher, you'd be teaching your students not to ask questions. Because if they do then the teacher makes them feel small. And your whole class would fail because you A: didn't teach clearly and B: taught them not to ask questions so they never got a full understanding.

Um, how about the fact that you never specified that you that you'd use rcon to exicute the object_create_anew command. You said you could have a script create a new vehicle with the press of a widget button. that leads me to believe that it wouldn't sync. then you said "by using rcon, have a continuous script running for all players that checks if that vehicle is within the trigger volume and if so set the permutation." you did not specify that rcon would be used to create the new vehicle. You could've worded it "what you could do is have a UI widget, using the rcon command, create an invisible vehicle inside of a trigger volume, And have a continuous script checking so when the vehicle is created, it executes the permutation command."
Edited by grunt_eater on Sep 16, 2012 at 08:00 PM


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 16, 2012 07:58 PM    Msg. 20 of 30       
No, but i did in the first post. I said that i wanted this for all players, that includes clients. So if a client pressed the button, then it's not out of the realm of possibility that the creation script would be executed on their PC. So it would not sync, then, with the other clients and the host. i was clear what i was looking for, you were not clear what your script would do.


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 16, 2012 08:30 PM    Msg. 21 of 30       
How about the fact that you never specified that the rcon command would be used in the creation script. You also said "using rcon, have a continuous script running for all players that checks if that vehicle is within the trigger volume and if so set the permutation." you never specified that the rcon would be for the creation script. So to me it sounded like the rcon command would be used for the second portion. As stated before, you could be much more clear about what you mean to say, child ;)


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 17, 2012 01:17 PM    Msg. 22 of 30       
Haha, cute. No, you just need to learn how to properly word\punctuate a sentence so it makes sense ;) but anyway. Back on topic now. If you're not going to help, then please leave.

(global short bubble 0)

(script dormant shield
(sleep_until (unit_get_current_flashlight_state (unit (list_get (players) 0))) 1)
(effect_new_on_object_marker "weapons\bubble_shield\effects\create_bubble" (unit (list_get (players) 0)) "body")
(set bubble 0))
)

(script continuous setup
(sleep_until (volume_test_object "bubble" (unit (list_get (players) 0)))
(set "bubble" 1)
(wake shield))
)

Any ideas as to why this doesn't compile?


Higuy
Joined: Mar 6, 2007

@lucasgovatos


Posted: Sep 17, 2012 01:51 PM    Msg. 23 of 30       
Quote: --- Original message by: grunt_eater
Haha, cute. No, you just need to learn how to properly word\punctuate a sentence so it makes sense ;) but anyway. Back on topic now. If you're not going to help, then please leave.

(global short bubble 0)

(script dormant shield
(sleep_until (unit_get_current_flashlight_state (unit (list_get (players) 0))) 1)
(effect_new_on_object_marker "weapons\bubble_shield\effects\create_bubble" (unit (list_get (players) 0)) "body")
(set bubble 0))
)

(script continuous setup
(sleep_until (volume_test_object "bubble" (unit (list_get (players) 0)))
(set "bubble" 1)
(wake shield))
)

Any ideas as to why this doesn't compile?


You know, it does tell you in sapien exactly why it wont compile. If you cant read it fast enough or whatever just open debug.txt.


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 17, 2012 04:15 PM    Msg. 24 of 30       
Sorry, that wasn't the actual script i used last night that i deleted before going to bed.

(global short bubble 0)

(script dormant shield
(sleep_until (unit_get_current_flashlight_state (unit (list_get (players) 0))) 1)
(effect_new_on_object_marker "weapons\bubble_shield\effects\create_bubble" (unit (list_get (players) 0)) "body")
(set bubble 0)
)

(script continuous setup
(sleep_until (volume_test_object "get_bubble" (unit (list_get (players) 0)))
(set "bubble" 1)
(wake shield))
)

The error it gives with this script is "i expected a long, bet this function returns a void "(wake shield))


Higuy
Joined: Mar 6, 2007

@lucasgovatos


Posted: Sep 17, 2012 04:28 PM    Msg. 25 of 30       
Becuase you have an extra ) at (wake shield)


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 17, 2012 11:01 PM    Msg. 26 of 30       
Thank you. The script compiled now, but in-game it didn't execute. Hmmmm. Any ideas?


MoooseGuy
Joined: Aug 10, 2008

I Approve This Message.


Posted: Sep 17, 2012 11:14 PM    Msg. 27 of 30       
You may find it more useful to avoid conflicts in the script by calling a static script instead of a dormant one. The current system you have makes it possible for it to call the dormant command a crap-ton of times if both checks return true. You should also put a sleep command in somewhere so you don't have the player flashing 30 times per second.

Also, you had a parenthesis issue with the flashlight check.

(global boolean bubble false) ;;<------------USE A BOOLEAN IF YOU ARE JUST SETTING 1 AND 0

(script static void shield
(sleep_until (unit_get_current_flashlight_state (unit (list_get (players) 0)) 1)) ;;<---------POSITION OF THE 1 HERE
(effect_new_on_object_marker "weapons\bubble_shield\effects\create_bubble" (unit (list_get (players) 0)) "body")
(set bubble false)
)

(script continuous setup
(sleep_until (volume_test_objects get_bubble (players))) ;;<------THIS CHECK IS MORE RELIABLE IN MY EXPERIENCE
(set bubble true)
(shield)
;;(sleep 300) <----I WOULD RECOMMEND A SLEEP FUNCTION OF SOME KIND TO PREVENT THE PLAYER FROM FLASHING EVERY FRAME WHEN BOTH CHECKS ARE TRUE.
)


If you don't call "shield" from any other scripts, I would recommend cleaning it up into one script.

(global boolean bubble false)

(script continuous setup
(sleep_until (volume_test_objects get_bubble (players)))
(set bubble true)
(sleep_until (unit_get_current_flashlight_state (unit (list_get (players) 0)) 1))
(effect_new_on_object_marker "weapons\bubble_shield\effects\create_bubble" (unit (list_get (players) 0)) "body")
(set bubble false)
;;(sleep 300)
)

Edited by MoooseGuy on Sep 17, 2012 at 11:20 PM


grunt_eater
Joined: Jan 26, 2011

Everything except biped rigging.


Posted: Sep 18, 2012 09:42 AM    Msg. 28 of 30       
When i tried making it a boolean before it crashed sapien. I don't know why, all i did was replace the 1's and 0's with true and false. Anyway, as for making it so if any player enters the trigger_volume it sets the global to true, that would make it so that if any player picks up a bubble shield, then player 0 is the only one who gets it. Lol. But thank you very much, i don't know why i never thought of putting two sleep_until's in a script before. Thanks for the tip ^_^


MoooseGuy
Joined: Aug 10, 2008

I Approve This Message.


Posted: Sep 18, 2012 11:53 AM    Msg. 29 of 30       
Wait, this is for multiplayer? My bad...


kirby_422
Joined: Jan 22, 2006

Apparently public enemy number 1?


Posted: Sep 18, 2012 12:42 PM    Msg. 30 of 30       
With your current script, that global is doing nothing regardless of what datatype you make it. You're doing a debug style; you only ever set the variable, never check it. This means you can go ingame, and use 'inspect <variable name>' to see what it is for your own personal knowledge, but the game itself doesn't care either way. Also, I don't see how you setting a number to 1 is meant to present player0... 0 is a better depiction of p0..

Anyways, if you want to use it in MP, you are going to have to assign all players to globals, so you can keep tracking them even when their numbers change. Whenever I get around to finishing that AA pdf for my script thread, it should help you greatly with understanding this (I really should bring that script with me to work on it while im sitting around waiting for class to start... I get here every day at 8:30AM, almost every day, I have to wait until 1PM for my first class.. quite a bit of spare time sitting at school...)

 

 
Previous Older Thread    Next newer Thread







Time: Thu January 19, 2023 5:05 AM 297 ms.
A Halo Maps Website