Noodle Posted March 13, 2015 Posted March 13, 2015 Hi guys, I've got a quick question and if anybody can help me I'd appreciate it a lot since it'd mean a whole new thing to explore for me. During these months I've been trying to learn how to script and map, and there's one command that I just can't understand and I haven't been successful at finding a tutorial at all. Can anybody explain to me (or point me at a tutorial) how does the "if" and "else" command works? I've seen it in a few SP maps (like Nar Shadda) but I can't imitate them at all. If anybody can help me, I'd be very grateful. p.s: excuse my english, it's not my language.
Xycaleth Posted March 13, 2015 Posted March 13, 2015 It's a way of doing something if a statement is true. If the statement isn't true, then the action after the else command is performed. Consider this sentence: "I'm going to go to the beach if the weather is nice, otherwise I'm going to stay in and play video games." You can rearrange this sentence to read: "If the weather is nice, I'm going to the beach. Otherwise, I'm going to stay in and play video games." In ICARUS, this would look something like: if ( weather is nice ) { go to beach } else ( ) { play video games }Alternatively, in something more game-related: if ( $get( FLOAT, "SET_PARM1")$, $=$, $1$ ) ) { print("SET_PARM1 is equal to 1") } else ( ) { print("SET_PARM1 is not equal to 1") } Noodle and Boothand like this
Noodle Posted March 13, 2015 Author Posted March 13, 2015 Thanks! I've been trying to do a simple script with the range attribute, but it doesn't seems to work. if ( $random( 0, 1 ) > 0.500$ ) { do ( "test1" ); wait ( "test1" ); else ( ) { do ( "test2" ); wait ( "test2" ); } } The idea was that it'd randomly choose to do a task (test1) or another (task2), yet it does not work. I thought it might be because I don't know how to add the third <expr>, I just typed 0.5, or maybe there is something else I'm unaware of.
mrwonko Posted March 13, 2015 Posted March 13, 2015 The else is not supposed to go inside the if, it should follow it. Noodle likes this
Noodle Posted March 13, 2015 Author Posted March 13, 2015 The else is not supposed to go inside the if, it should follow it. I hadn't noticed that. I was using this script from ns_streets as reference. There's an if inside an else, I don't get how that works. affect ( "kyle", FLUSH ) { task ( "going" ) { sound ( CHAN_VOICE, "sound/chars/kyle/09kyk018.mp3" ); } task ( "going_on" ) { sound ( CHAN_VOICE, "sound/chars/kyle/09kyk019.mp3" ); } task ( "join_you" ) { sound ( CHAN_VOICE, "sound/chars/kyle/09kyk020.mp3" ); } if ( $random( 0, 1 ) > 0.500$ ) { do ( "join_you" ); wait ( "join_you" ); run ( "ns_streets/bar_conv1b" ); } else ( ) { if ( $random( 0, 1 ) > 0.500$ ) { do ( "going" ); wait ( "going" ); run ( "ns_streets/bar_conv1b" ); } else ( ) { do ( "going_on" ); wait ( "going_on" ); run ( "ns_streets/bar_conv1b" ); } } }
mrwonko Posted March 14, 2015 Posted March 14, 2015 As a flow chart, that script looks roughly like this. Noodle likes this
Noodle Posted March 14, 2015 Author Posted March 14, 2015 As a flow chart, that script looks roughly like this.Thanks a lot! That's really helpful, hopefully I'll be able to do something nice with this knowledge.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now