home home

downloads files

forum forum

docs docs

wiki wiki

faq faq

Cube & Cube 2 FORUM


Scripting help required for terrain prefab

by Bascule on 08/06/2002 00:28, 16 messages, last message: 08/10/2002 22:18, 1387 views, last view: 05/01/2024 23:46

Code for terrain prefab below. I know it's long-winded, but I can't find a way to get the second part into a loop (to move down a row at a time), because I can't execute the row* alias from within a loop and still keep the argument with it.
In any case, it would be much better if the vdeltas could be calculated, rather than putting them in an argument at all, as I dread to think what the code would look like for a really big hill!
Would much appreciate some help from you code-monkeys out there with cleaning-up and optimising the code :)

// Generates a small hill. Use the alias 'hill' with no arguments.

// This section selects the square hill area using the current selection as the middle, sets the heightfields and also a few variables for future use.

selx (- $selx 5)
sely (- $sely 5)
selxs 11
selys 11

editheight 0 2
heightfield 0

alias xstart $selx
alias xmax (+ $selxs 1)
alias ymax (+ $selys 1)

selxs 1
selys 1

//each of these aliases sets up a loop to modify the vdeltas of *one* row of the selected hill area. This has to be done because the argument for the 'row*' alias is different for each row.

alias row1 [
loop $xmax [
at $arg1 $i
vdelta $s
selx (+ $selx 1)
]
selx $xstart
]

alias row2 [
loop $xmax [
at $arg1 $i
vdelta $s
selx (+ $selx 1)
]
selx $xstart
]

//etc., etc. for aliases row3 to row11

alias row12 [
loop $xmax [
at $arg1 $i
vdelta $s
selx (+ $selx 1)
]
selx $xstart
]

//the 'hill' alias executes the 'row' alias with an argument containing the vdelta values, then just increments the row selection and calls the next row alias.

alias hill [
row1 "8 8 8 8 8 8 8 8 8 8 8 8"
sely (+ $sely 1)
row2 "8 8 8 7 7 7 7 7 7 8 8 8"
sely (+ $sely 1)

//etc., etc. for row3 to row10

row11 "8 8 8 7 7 7 7 7 7 8 8 8"
sely (+ $sely 1)
row12 "8 8 8 8 8 8 8 8 8 8 8 8"
]


// EOF

   Board Index   

#1: Too tired to think properly last night...

by Bascule on 08/06/2002 09:17

I think that this should be able to be condensed into two neat loops, preferably nested, although I'm not sure if Cube can nest loops, as they would both use the alias 'i' placeholder.
Aard, can you confirm?
The biggest problem I seem to have is executing an alias *with arguments* from another alias, it seems that arguments can only be passed in by directly executing an alias.
Any further help much appreciated.

reply to this message

#2: Re: Too tired to think properly last night...

by pushplay on 08/06/2002 11:22, refers to #1

I think maybe you're still a little tired :). You don't need to use 'i.' Take a look at my buildmenu function, the loops go 2 deep (and I will show off and point out that it is thus O(n^2)). I don't think any language would be of much use with neither nestled loops nor recursion.

Your second problem. Consider the following:
alias a 5;
alias b 10;
executingalias $a $b;

Of course I've defined a and b at compile time, but that needn't be the case. I could always go:
alias a (* $a $a);
So you can see that a could take on any value.

Heh, maybe I should just write a tutorial, although that's a pretty large undertaking. Is there anything you could trade me in return Aard? ;)

reply to this message

#3: Re: Too tired to think properly last night...

by SleepwalkR on 08/06/2002 11:44, refers to #2

Pushplay, there were indeed programming languages without recursion, and as you should know if you study computer science, you can translate every recursive function into an iterative one using an explicit stack.

Now I'm showing off, I know.

reply to this message

#4: Re: Too tired to think properly last night...

by Bascule on 08/06/2002 14:01, refers to #2

Thanks - I think I can make this more elegant now - will work on it this week.

Also, despite what I said in another thread, I did not have your *latest* cubemods.

But now I have and, wow, I'm very impressed. I'll disect some of the more complex stuff for future reference.

Loved the Randomiser, but I think it could have been even more tight:

alias random [
alias total (listlen $arg1);
at $arg1 (rnd $total);
$arg2 $s;
]

Hey, I'm learning all the time!

or even? Not sure if this would be OK, I can't check while I'm at work [damn corporate PC's without OpenGL] :(

alias random [
at $arg1 (rnd (listlen $arg1));
$arg2 $s;
]

reply to this message

#5: Re: Too tired to think properly last night...

by pushplay on 08/06/2002 22:22, refers to #4

Apparently I was pretty tired last night too. There is no compile time. Strike that out and pretend I said "at the time of the writing of the script," only pretend that I said it more elegantly.

SleepwalkR: "neither nestled loops nor recursion," as in not having either. I recall being told that all recursive functions could be made iterative, but not necessarily the other way around. But I can't think of an iterative example that couldn't be made recursive if you could pass multiple paramaters back and forth (like with an array of Objects in Java).

Bascule: interesting, where is listlen in the readme? I can't find it. Assuming it does what it looks like it does, then your second example should be correct. It would also make \0 unecessary.

reply to this message

#6: Re: Too tired to think properly last night...

by Bascule on 08/07/2002 00:13, refers to #5

damn, refreshed page by accident - lost long post. Grrr... Try again:

listlen does not appear in the readme, but hey, nor does 'rnd $num' which you are using OK.

It appears in the menus.cfg in the alias genmapitems which is v. similar to your buildmenu function, but without the complexity of creating the newmenu alias, just the menuitems.

Anyway, I've fixed my script problems, I can now snip one argument of many from an alias and pass it through as a single argument to another alias, which was the problem I had. Have now got all the above code down to one alias and two neat loops :))

Hills are looking good :)

Too tired again to tidy up and re-publish, but will later. That's what having two children does to you :/

reply to this message

#7: Re: Too tired to think properly last night...

by pushplay on 08/07/2002 01:41, refers to #6

Good thing I saved the original menu and autoexec for just such an occasion. The buildmenu does something that genmapitems doesn't which is splitting up the list into submenus of a managable length. I also generalised buildmenu so that I use it for selecting skyboxes and music.

I'll update the script to use listen and remove the need for \0.

reply to this message

#8: dear sirs...

by pushplay on 08/07/2002 06:17, refers to #7

The script is now updated to use listlen and I've removed the \0 from the lists. Because I've split the lists into a seperate file (for just such an occasion), anyone using cfgs similar to mine can just strip out the \0 and not have to overwrite their list and go back over it.

There's also a new function in there called superpaste. The function will paste the clipboard into a selection as many times as it will fit, with a minimum of one paste. So if you copied a 1x1 cube it would be pasted into every square of any size of selection. If you copied a 2x1 section and tried to paste into a 1x1 section it would be pasted once. Finally, if you copied a 2x1 section and pasted it into a 5x3 section, it would be pasted 6 times like so:
___________
|x|x|x|x| |
-----------
|x|x|x|x| |
-----------
|x|x|x|x| |
-----------

so that the right most column wouldn't be touched. It's a little hard to explain, but if you play with it a little I think you'll find that it's pretty simple.

reply to this message

#9: address

by pushplay on 08/07/2002 06:18

http://members.shaw.ca/pushplay/cube/mods/

reply to this message

#10: Nothing works when I try it late at night

by Bascule on 08/08/2002 09:16, refers to #9

Downloaded new mods - no changes? Maybe I downloaded too soon.

Anyway, I haven't solved my original problem, one small thing required.

I'm trying to put the text "$arg" in an alias so that I can concatword it with a loop value in order to snip out a specific argument from a list of arguments and then pipe it to another alias i.e.:

alias snip1 "$arg"

alias FuncWithNineArgs
loop 9 [
alias snip2 (+ $i 1)
concatword $snip1 $snip
FuncNeedsOneArg $s
]
]

This would execute FuncNeedsOneArg nine times, passing the nine arguments supplied to FuncWithNineArgs one at a time.

It doesn't work because 'alias snip1 "$arg"' tries to put the value of non-existent alias 'arg' into snip1, when I want the text string '$arg' to be put in.
I've tried alias snip1 [$arg] and alias snip1 ($arg) with no success

The only solution I can come up with, so far untested as I came up with it over breakfast this morning, is:

at "blank $arg" 1
alias snip1 $s

Any ideas from anyone if this would work?

reply to this message

#11: *sigh*

by pushplay on 08/08/2002 10:51

I'm getting annoyed with my isp. Any changes I make to html files and upload to the ftp server are automatically reflected accessed through http. The same isn't true for zip files, yet if I make a new zip file instead of replacing it, it can be accessed through http immediatly. They must be doing some kind of wacky assed caching which is screwing me over.

As a temp solution you can grab the file here:
http://members.shaw.ca/pushplay/cube/mods/cubemods2.zip

I see what your problem is. Yeah, Cube is trying to find the alias $arg and evaluate it. I would try to avoid using the dollar sign at all costs. But if you can't... that method does seem to work. You just need to keep the dollar sign from being the first character I believe. So if you just want it as text to write out, you could also go:

\t alias snip1 " $arg"

reply to this message

#12: Re: *sigh*

by Bascule on 08/08/2002 11:02, refers to #11

I don't want it written out, I want '$arg' to be held by an alias as a lump of text, so that I can use it to concatword.

When you say '..that method seems to work', do you mean that the

at "blank $arg" 1
alias snip1 $s

code works? Have you tried it?

Thanks for your help and I've got your new cubemods now :)

reply to this message

#13: Re: *sigh*

by pushplay on 08/08/2002 23:07, refers to #12

I tried it, I just typed it into the console. I like doing that. It's like programming at execution time.

reply to this message

#14: Re: *sigh*

by Bascule_in_library on 08/09/2002 11:16, refers to #13

It does kinda work, but my script as whole still doesn\'t :((

I\'m still looking for an answer to my post #10 in terms of a complete working alias.

Anyone????

reply to this message

#15: $arg in a string

by Aardappel on 08/09/2002 18:50

will not work, since cube will stubbornly keep replacing it :)

if you want to work with variable arguments, its much better to simply pass a list and pick elements from that, i.e. instead of

myalias arg1 arg2 arg3

do

myalias "arg1 arg2 arg3"

reply to this message

#16: Re: $arg in a string

by Bascule on 08/10/2002 22:18, refers to #15

Thanks for that Aard. I did try a couple of other things, but they did not work.

I'll re-structure to use one mega-argument!

reply to this message

   Board Index   


Unvalidated accounts can only reply to the 'Permanent Threads' section!


content by Aardappel & eihrul © 2001-2024
website by SleepwalkR © 2001-2024
53869599 visitors requested 71644796 pages
page created in 0.033 seconds using 10 queries
hosted by Boost Digital